Skip to content

Instantly share code, notes, and snippets.

@tientp-floware
Created March 30, 2021 03:34
Show Gist options
  • Save tientp-floware/71ce9fb338d3ae46746991ac19c70116 to your computer and use it in GitHub Desktop.
Save tientp-floware/71ce9fb338d3ae46746991ac19c70116 to your computer and use it in GitHub Desktop.
Nestjs validator array of object
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