Browse Source

block unblock

master
Pheuw1 2 years ago
parent
commit
bb2bf1d0c7
  1. 18
      back/volume/src/users/users.controller.ts

18
back/volume/src/users/users.controller.ts

@ -37,6 +37,24 @@ export class UsersController {
private readonly usersService: UsersService, private readonly usersService: UsersService,
) {} ) {}
@UseGuards(AuthenticatedGuard)
@Post("block/:id")
async blockUser(@Profile42() profile :Profile, @Param('id') id:number) {
const user = await this.usersService.findUser(id) as User
user.blocked.push((await this.usersService.findUser(+profile.id)) as User)
this.usersService.save(user);
}
@UseGuards(AuthenticatedGuard)
@Post("unblock/:id")
async unblockUser(@Profile42() profile :Profile, @Param('id') id:number) {
const user = await this.usersService.findUser(id) as User
user.blocked = user.blocked.filter((usr: User) => {
return usr.id !== id
})
this.usersService.save(user);
}
@Get('all') @Get('all')
async getAllUsers (): Promise<User[]> { async getAllUsers (): Promise<User[]> {
return await this.usersService.findUsers() return await this.usersService.findUsers()

Loading…
Cancel
Save