class validator validate nested object

Solutions on MaxInterview for class validator validate nested object by the best coders in the world

showing results for - "class validator validate nested object"
Nicole
27 Jul 2017
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}
Phoebe
21 Jan 2016
1class-validator