showing results for - "nestjs class validator"
Deborah
22 Apr 2020
1import {
2  MinLength,
3  MaxLength,
4  IsNotEmpty,
5  ValidateNested,
6  IsDefined,
7  IsNotEmptyObject,
8  IsObject,
9  IsString,
10} from 'class-validator';
11import { Type } from 'class-transformer';
12
13class MultiLanguageDTO {
14  @IsString()
15  @IsNotEmpty()
16  @MinLength(4)
17  @MaxLength(40)
18  en: string;
19
20  @IsString()
21  @IsNotEmpty()
22  @MinLength(4)
23  @MaxLength(40)
24  ar: string;
25}
26
27export class VideoDTO {
28  @IsDefined()
29  @IsNotEmptyObject()
30  @IsObject()
31  @ValidateNested()
32  @Type(() => MultiLanguageDTO)
33  name!: MultiLanguageDTO;
34}
Marta
29 Sep 2018
1useContainer(app.select(AppModule), { fallbackOnErrors: true });
2
3@ValidatorConstraint({ name: 'UserExists', async: true })
4@Injectable()
5export class UserExistsRule implements ValidatorConstraintInterface {
6  constructor(private usersRepository: UsersRepository) {}
7
8  async validate(value: number) {
9    try {
10      await this.usersRepository.getOneOrFail(value);
11    } catch (e) {
12      return false;
13    }
14
15    return true;
16  }
17
18  defaultMessage(args: ValidationArguments) {
19    return `User doesn't exist`;
20  }
21}
22
23export function UserExists(validationOptions?: ValidationOptions) {
24  return function (object: any, propertyName: string) {
25    registerDecorator({
26      name: 'UserExists',
27      target: object.constructor,
28      propertyName: propertyName,
29      options: validationOptions,
30      validator: UserExistsRule,
31    });
32  };
33}
34
35
queries leading to this page
class validator nestjs isbooleanclass validator nestnestjs class validator message propertycontains nestjs class validatornested validation class validatorsclass validator nestjs examplevalidator for nested objectsnestjs class validator examplevalidate nested class validatornestjs class validationclass validator for nestjsclass validator nested objectnestjs class validator typeoptionsnestjs validateclassnest class validatornest js 2c class validator 2c custom validationsnestjs class validator register custom decoratornestjs install class validatorclass validator nestjs listclass validator nested objectsnestjs class validatorclass validator nestjsclass validator nested errorsclass validator set up in nest jsnodejs validate nested object class validatorclass validators nestjsclass validator validate complex nested objectclass validator validate nested object propertiesclass validator validate nested objecthow to validate nested objectsclass validator nested object validationclass validation nestjsvalidating nested objects class validatornestjs class validatornest custom class validatornestjs class validator add messagecustom class validator in nestjsnest js validate object to classclass validator nestjs decoratorsnestjs class validator 5cclass validator nest jsclass validator in nestjscustom class validator nestjsclass validator nested objectnestjs class validator messageclass validator nestjscustom validation nestjs class validatorclass validator in nestjsnestjs class validator nested objectclass validator nestnest class validatorclass validator validate nested objecthow to override class validator in nestjsnestjs class validator custom object custom validator nestjs class validatornestjs class validator