I have a code in which i have applied a global validation pipe in main.ts file like so:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
// Enable global validation pipe
app.useGlobalPipes(new ValidationPipe({
whitelist: true
}));
}
Now in one of my controller i wanted to skip some properties of a DTO in a patch request like so
@Patch(':id')
// Override the pipes
@UsePipes(new ValidationPipe({
skipMissingProperties: true,
}))
updateProject(@Param('id') accountId: string, @Body() dataToUpdate: UpdateProjectDTO) {
return dataToUpdate;
}
This is my DTO:
export class UpdateProjectDTO {
@IsNotEmpty()
projectType: string;
@IsNotEmpty()
projectDescription: string;
}
I wanted to ignore projectDescription if its not submitted as part of the request. But in this case my global pipe is taking precedence which doesn't have skipMissingProperties defined as part of its property. Is there a solution to override the global pipe?