import { ApiProperty } from '@nestjs/swagger';
import { IsString, ValidateNested } from 'class-validator';
export class TestDto {
@ApiProperty()
test: string;
}
export class UserReqDto {
@ApiProperty()
@IsString()
id: string;
@ApiProperty()
@ValidateNested({ each: true })
data: object;
}
const sampleData = {
id: 'asbd',
data: {
['any dynamic key 1']: {
test: '1',
},
['any dynamic key 2']: {
test: '2',
},
},
};
Here UserReqDto is my main DTO and TestDto is child DTO.
I need to validate sampleData type of data.
How can I do that?
in data field i need to validate object of TestDto type's objects