UNPKG

nestjs-custom-class-validators

Version:

This package contains a few custom validator I have found to be repetitive, So I made templates that handles both class-validator checks and Swagger configuration

21 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomTimeValidator = void 0; const class_validator_1 = require("class-validator"); const commonDecoratorFunctions_1 = require("../utils/commonDecoratorFunctions"); function CustomTimeValidator(details) { const { optional, defaultValue, isArray, description } = details; const mySwaggerProp = (0, commonDecoratorFunctions_1.swaggerProp)({ optional, description, defaultValue, type: isArray ? 'array' : 'string', }); return function (target, key) { optional ? (0, class_validator_1.IsOptional)()(target, key) : (0, commonDecoratorFunctions_1.notEmptyFn)(key)(target, key); (0, class_validator_1.Matches)(new RegExp('(0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]'), Object.assign({ message: `${key}: Must be a valid 24h time` }, (isArray && { each: true })))(target, key); mySwaggerProp(target, key); }; } exports.CustomTimeValidator = CustomTimeValidator; //# sourceMappingURL=time.decorator.js.map