I found related issue: https://github.com/nestjs/nest/issues/2470
#Can I use ValidationPipe outside of the controller?
3 messages · Page 1 of 1 (latest)
example:
import { IsNumber, IsString } from 'class-validator';
import { UsePipes, ValidationPipe } from '@nestjs/common';
export class Params {
@IsNumber()
min!: string;
@IsNumber()
max!: number;
@IsString()
stat!: string;
}
export class A {
@UsePipes(new ValidationPipe())
validate(args: Params): Promise<boolean> {
console.log('A args', args);
return Promise.resolve(true);
}
}
No. Since Nest has no control over which functions you call directly from your code, it can only intercept calls before it hands over control to your code - that is, between receiving the request and calling your controller method.