import { registerDecorator , ValidationOptions , ValidatorConstraint , ValidatorConstraintInterface , } from 'class-validator' ; @ ValidatorConstraint ( { async : true } ) export class FindDuplicateEmailsConstraint implements ValidatorConstraintInterface { validate ( emailList ) { const checkedEmails = { } ; for ( let i = 0 ; i <= emailList . length ; i ++ ) { if ( emailList [ i ] in checkedEmails ) { return false ; } checkedEmails [ emailList [ i ] ] = 1 ; } return true ; } } export function FindDuplicateEmails ( validationOptions ? ) { return function ( object , propertyName ) { registerDecorator ( { target : object . constructor , propertyName : propertyName , options : validationOptions , constraints : [ ] , validator : FindDuplicateEmailsConstraint , } ) ; } ; }