Validation with Custom Decorators: Quick NestJS sample
Unlock the full potential of data validation in your NestJS applications by learning how to create custom decorators! In this detailed tutorial, we delve into the power of the class-validator library and show you how to craft a versatile IsNumber decorator. This custom decorator not only checks if a value is a number but also lets you specify minimum and maximum values for enhanced data integrity.
import { applyDecorators } from '@nestjs/common';
import { IsNumber as IsNumberBase, Min, Max } from 'class-validator';
import { DEFAULT_MIN, DEFAULT_MAX } from '../constants/number-fields.constants';
type TIsNumberOptions = {
min?: number;
max?: number;
};
export default function IsNumber(options?: TIsNumberOptions) {
const { min = DEFAULT_MIN, max = DEFAULT_MAX } = options || {};
return applyDecorators(IsNumberBase(), Min(min), Max(max));
}
Видео Validation with Custom Decorators: Quick NestJS sample канала Blue Cell
import { applyDecorators } from '@nestjs/common';
import { IsNumber as IsNumberBase, Min, Max } from 'class-validator';
import { DEFAULT_MIN, DEFAULT_MAX } from '../constants/number-fields.constants';
type TIsNumberOptions = {
min?: number;
max?: number;
};
export default function IsNumber(options?: TIsNumberOptions) {
const { min = DEFAULT_MIN, max = DEFAULT_MAX } = options || {};
return applyDecorators(IsNumberBase(), Min(min), Max(max));
}
Видео Validation with Custom Decorators: Quick NestJS sample канала Blue Cell
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
Copy and paste multiple items at the same time for MacOSBoost Your Git Workflow with Aliases: Quick GuideHow to make Git detect filename case changes: A Quick FixHow to make checkbox as required field for yup validation?Utilize React Router State for Seamless Data Passing: Quick GuideSpeed Up Coding with VSCode Snippets: From Zero to HeroHandover – один из основных принципов сотовой связи. Что это такое и для чего он нужен?Основной принцип построения сотовой связи. Откуда берутся соты и существуют ли они на самом деле?Транкинговая система мобильной связи. Радиальная система мобильной связиЗамирание сигнала в радиоканалеВозникновение и история мобильной связиВ чем разница между 1G, 2G, 3G и 4G? Детальный обзорКак изменить язык интерфейса Windows, если лицензия Windows поддерживает только один язык интерфейсаImprove you code style: Adding ESLint and PrettierAutomate Your Coding Style: Set Up ESLint Auto-Formatting in VSCode