Assign role route
A route for the admin to assign roles to other users.
export class RoleDto {
@IsEnum(Role)
readonly role: Role;
}@Patch(':id/assign-role')
assignRole(@Param() { id }: IdDto, @Body() { role }: RoleDto) {
return this.authService.assignRole(id, role);
}async assignRole(id: number, role: Role) {
const user = await this.usersRepository.preload({
id,
role,
});
if (!user) {
throw new NotFoundException('User not found');
}
return this.usersRepository.save(user);
}Last updated