nestjs nested route

◾️ how to route nested url ( ex – /users/:id/subjects/:subjectId)

.....
@Controller('users')
export class UserController {
  constructor(private readonly userService: UsersService) {}
  // @Post @Delete @Get....
  @Patch(':id/subjects/:subjectId')
  updateSubject(
    @Param('id') id: number,
    @Param('subjectId') subjectId: number,
    @Body() updateSubject: UpdateSubjectDto,
  ) {
    return this.userService.updateSubject(id, updateSubject, subjectId);
  }
}
....

◾️ advanced method adding controller for nested route

.....
@Controller('users')
export class UserController {
  ......
}

@Controller('users/:id')
export class SubjectController {
  ......
  @Patch('/subjects/:subjectId')
  updateSubject(
    @Param('id') id: number,
    @Param('subjectId') subjectId: number,
    @Body() updateSubject: UpdateSubjectDto,
  ) {
    return this.userService.updateSubject(id, updateSubject, subjectId);
  }
}
....

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です