我有一个 NestJS 控制器:
@Controller('users')
@ApiTags('users')
export class UserController {
constructor(
private userService: UserService,
private userRoleService: UserRoleService,
private readonly translationService: TranslationService,
) {}
@Get('organization-admin')
@AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOkResponse({
description: 'Access for organization admin granted'
})
async organizationAdmin(@AuthUser() user: UserEntity): Promise<string> {
return `Hello organization admin ${user.firstName}`;
}
@Post(':id/assign-role')
@AuthorizeFor(RoleType.ORGANIZATION_ADMIN)
@HttpCode(HttpStatus.OK)
@ApiOkResponse({
status: HttpStatus.OK,
description: 'Role assigned to user',
type: UserRoleDto,
})
async assignRoleToUser(
@Body() userRole: CreateUserRoleDto,
@UUIDParam('id') userId: string
): Promise<CreateUserRoleDto> {
const user = await this.userService.findOne({ id: userId });
return this.userRoleService.createUserRole(user, userRole);
}
}
使用 swagger - Bearer 令牌附加到请求@Get('organization-admin')
但不会附加到@Post(':id/assign-role')
.
你能帮我弄清楚为什么会发生吗?
提前致谢。