How to validate object using class-validator again after receive from @Body() of nestjs?

74 Views Asked by At

I try this approach but when I enter input that shouldn't pass when validate it return []

import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { MyDTO } from './MyDTO';

const body = { name: 'John', age: '25' }; 
const myDtoInstance = plainToClass(MyDTO, body);

console.log(await validate(myDtoInstance))


Edited: This work but in my MyDTO It's like this

class MyDTO {
datas: DataDTO

}

class DataDTO{
 @Length(10,30)
 name: string
}

The validator in DataDTO not run

0

There are 0 best solutions below