#Can we use ValidationPipe and @UsePipes in `_.service.ts` files?
3 messages · Page 1 of 1 (latest)
I think you may have confused the meaning of dtos and pipes...
A dto for an entity in your database for example means data that the user sends to your service, which should have some fields, each with its' own type.
This data can (and should) be validated with pipes such as the validation pipe.
A pipe by definition stands between the client to your route handler, so this is the only place where pipes can be used.
Basically what this means and the purpose of the ValidationPipe is to validate the data the client sends in the payload of a request to your route handler.
Only if the data is valid will the route handler be invoked, otherwise an error will be thrown.
Hopefully this answers your question...
To asnwer in short - no, you cannot use pipes on service method. At that point it's your code (controller) calling the servicd method, so Nest does not have any way of interposing logic there.