import type { ValidationOptions } from 'class-validator' ; import { IsPhoneNumber as isPhoneNumber , registerDecorator , ValidateIf , } from 'class-validator' ; import { isString } from 'lodash' ; export function IsPassword ( validationOptions ? ) { return ( object , propertyName ) => { registerDecorator ( { propertyName , name : 'isPassword' , target : object . constructor , constraints : [ ] , options : validationOptions , validator : { validate ( value ) { return /^[\d!#$%&*@A-Z^a-z]*$/ . test ( value ) ; } , } , } ) ; } ; } export function IsPhoneNumber ( validationOptions ? ) { return isPhoneNumber ( validationOptions ?. region , { message : 'error.phoneNumber' , ... validationOptions , } ) ; } export function IsTmpKey ( validationOptions ? ) { return ( object , propertyName ) => { registerDecorator ( { propertyName , name : 'tmpKey' , target : object . constructor , options : validationOptions , validator : { validate ( value ) { return isString ( value ) && /^tmp\// . test ( value ) ; } , defaultMessage ( ) { return 'error.invalidTmpKey' ; } , } , } ) ; } ; } export function IsUndefinable ( options ? ) { return ValidateIf ( ( obj , value ) => value !== undefined , options ) ; } export function IsNullable ( options ? ) { return ValidateIf ( ( obj , value ) => value !== null , options ) ; }