Complete the code to define a route parameter named 'id' in a NestJS controller method.
@Get(':[1]') getItem(@Param('id') id: string) { return `Item ID is ${id}`; }
The route parameter name must match the string inside the @Get decorator. Here, ':id' defines the parameter 'id'.
Complete the code to extract the 'userId' route parameter in the controller method.
@Get('user/:userId') getUser(@Param('[1]') userId: string) { return `User ID is ${userId}`; }
The string inside @Param must match the route parameter name 'userId' to extract its value.
Fix the error in the code to correctly define and use a route parameter named 'postId'.
@Get(':[1]') getPost(@Param('postId') postId: string) { return `Post ID is ${postId}`; }
The route parameter name in the @Get decorator must match the string used in @Param. Here, both should be 'postId'.
Fill both blanks to create a route with two parameters 'category' and 'itemId' and extract them in the method.
@Get(':[1]/:[2]') getItem(@Param('[1]') category: string, @Param('[2]') itemId: string) { return `Category: ${category}, Item ID: ${itemId}`; }
The route parameters and the strings inside @Param must match exactly. Here, 'category' and 'itemId' are used consistently.
Fill all three blanks to create a route with parameters 'user', 'postId', and 'commentId' and extract them in the method.
@Get(':[1]/:[2]/:[3]') getComment( @Param('[1]') user: string, @Param('[2]') postId: string, @Param('[3]') commentId: string ) { return `User: ${user}, Post: ${postId}, Comment: ${commentId}`; }
Each route parameter must be defined with a colon and match the string inside the corresponding @Param decorator.