validate nested objects using class-validator in nest.js controller

Try specifying the nested type with @Type:

import { Type } from 'class-transformer';

export class CurrencyDTO {
  @ValidateNested({ each: true })
  @Type(() => Data)
  data: Data[];
}

For a nested type to be validated, it needs to be an instance of a class not just a plain data object. With the @Type decorator you tell class-transformer to instantiate a class for the given property when plainToClass is called in your VaildationPipe.

If you are using the built-in ValidationPipe make sure you have set the option transform: true.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)