parametersnestjsquery-string

Nestjs default param mapping


I have this controller method below, that I want to be able to call like I want to call the method like add/1:

@Controller()
export class MyController {

  @Post('add/:id')
  async add(@Body() data: MyData, @Query('id') id?: number) {
     console.log(id);
     //...
  }
}

Is it possible to achieve without modifying the Controller like Controller('add') ?


Solution

  • try change @Query to @Param

    @Post('add/:id')
      async add(@Body() data: MyData, @Param('id') id?: number) {
         console.log(id);
         //...
      }