Created
March 30, 2021 03:34
-
-
Save tientp-floware/71ce9fb338d3ae46746991ac19c70116 to your computer and use it in GitHub Desktop.
Nestjs validator array of object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IsString, IsNumber, IsArray, ValidateNested, ArrayMinSize, ArrayMaxSize } from 'class-validator'; | |
import { Type } from 'class-transformer'; | |
export class SMa1 { | |
@IsNumber() | |
id: number; | |
@IsString() | |
type: string; | |
@IsString() | |
value: string; | |
} | |
export class SMa1DTO { | |
@IsArray() | |
@ValidateNested({ each: true }) | |
@ArrayMinSize(2) | |
@ArrayMaxSize(2) | |
@Type(() => SMa1) | |
MSMa1: SMa1[]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment