#How can i stack decorators for controller routes
10 messages · Page 1 of 1 (latest)
The code you sent is totally okay and should work. Nest allows you to use decorators like that.
Any Patch or PUT request will be caught by the updateBooking method, so if you have any methods below the updateBooking, move them higher as the definition order matters.
I've tried that.. something else is happened
@hushed lynx Very weird .. not sure if its something with how i set up the project or something broader then then just this
Can you elaborate?
When asking for help with a problem, don't just say, "X doesn't work" or "Y did not fix it" actually describe the error.
If there is an error message, share it. If it did not function as expected, describe how it behaved and how you expected it to behave.
If you haven't already, or haven't recently, share the code that is not working and any code we may need to help diagnose the error.
Sure, well its my first nest project i pretty much followed the tutorial
There was other weird issues that i some how overcame
for example:
@Post(':id')
@UsePipes(new ValidationPipe())
patchBooking(
@Param('id') id: number,
@Body(ValidateBookingPipe) bookingDetails: BookingDetails,
@Req() req: Request & { user: User }
): Promise<Booking> {
return this.updateBooking(id, req.user, bookingDetails);
}
the ValidateBookingPipe wont run at all however
when i do
@UsePipes(ValidateBookingPipe, new ValidationPipe())
it does work
As for my current issue:
@Put(':id')
@Patch(':id')
@UsePipes(ValidateBookingPipe, new ValidationPipe())
putBooking(
@Param('id') id: number,
@Body() bookingDetails: BookingDetails,
@Req() req: Request & { user: User }
): Promise < Booking > {
return this.updateBooking(id, req.user, bookingDetails);
}
the Put route does work patch does not
You aren't able to stack decorators like that. That's not how Nest's outing decorators are designed to work
Ah !! there we go is there another way other then having a their none routed method that both of the routes call ?
Its funny serveral people said that its possible to stack them including chatGPT 🙂