#How can i stack decorators for controller routes

10 messages · Page 1 of 1 (latest)

haughty geyser
#

I've tried the following but only the first only works:

@Put('/:id')
  @Patch('/:id')
  updateBooking(
  ): boolean {
    return true;
  }
hushed lynx
haughty geyser
#

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

hushed lynx
#

Can you elaborate?

smoky agateBOT
#

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.

haughty geyser
# hushed lynx Can you elaborate?

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

tiny salmon
#

You aren't able to stack decorators like that. That's not how Nest's outing decorators are designed to work

haughty geyser
#

Its funny serveral people said that its possible to stack them including chatGPT 🙂