Skip to content
Snippets Groups Projects
Commit 29305d75 authored by L4168's avatar L4168
Browse files

custom validation for uuid and null

parent 6e88e9a8
No related branches found
No related tags found
4 merge requests!59Development to master,!31Development,!25Dto service,!24Faction task edit
import {
ValidatorConstraint,
ValidatorConstraintInterface,
ValidationArguments,
Validator,
} from 'class-validator';
// check if input is null or valid uuid
@ValidatorConstraint({ name: 'uuid', async: true })
export class Uuid implements ValidatorConstraintInterface {
validate(uuid: string, args: ValidationArguments) {
const validator = new Validator();
return validator.isUUID(uuid, '4') || uuid == null; // for async validations you must return a Promise<boolean> here
}
defaultMessage(args: ValidationArguments) {
return 'Not valid uuid';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment