Skip to content
Advertisement

ValidationPipe doesn’t strip given object in Nestjs

I’m using Nestjs and Mongoose orm the problem is ValidationPipe doesn’t delete invalid props from request and send given(raw) request to my service.

This is main.ts

JavaScript

and this is update-category.dto

JavaScript

And finally this is category.service

JavaScript

Here is my simple controller

JavaScript

when “given categories” logs items, they have _id which frontend sent to api while I didn’t whitelisted that props in my dto. why I’m receaving that prop?? I also tried `forbidNonWhitelisted’ and interestingly request didn’t fail :)) seems useGlobalPipes doesn’t work for me

Advertisement

Answer

Just use ParseArrayPipe.

Update your controller.ts:

JavaScript

Ensure to have items and whitelist set.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement