Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 44 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Controller, |
||
3 | Inject, |
||
4 | BadRequestException, |
||
5 | UseGuards, |
||
6 | Param, |
||
7 | Delete |
||
8 | } from '@nestjs/common'; |
||
9 | import { AuthGuard } from '@nestjs/passport'; |
||
10 | import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; |
||
11 | import { ICommandBus } from 'src/Application/ICommandBus'; |
||
12 | import { RemoveUserCommand } from 'src/Application/User/Command/RemoveUserCommand'; |
||
13 | import { UserRole } from 'src/Domain/User/User.entity'; |
||
14 | import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
15 | import { Roles } from 'src/Infrastructure/User/Decorator/Roles'; |
||
16 | import { RolesGuard } from 'src/Infrastructure/User/Security/RolesGuard'; |
||
17 | import { LoggedUser } from '../Decorator/LoggedUser'; |
||
18 | import { UserAuthView } from '../Security/UserAuthView'; |
||
19 | |||
20 | @Controller('users') |
||
21 | @ApiTags('User') |
||
22 | @ApiBearerAuth() |
||
23 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
24 | export class RemoveUserAction { |
||
25 | constructor( |
||
26 | @Inject('ICommandBus') |
||
27 | private readonly commandBus: ICommandBus |
||
28 | ) {} |
||
29 | |||
30 | @Delete(':id') |
||
31 | @Roles(UserRole.PHOTOGRAPHER) |
||
32 | @ApiOperation({ summary: 'Remove user' }) |
||
33 | public async index( |
||
34 | @Param() { id }: IdDTO, |
||
35 | @LoggedUser() user: UserAuthView |
||
36 | ) { |
||
37 | try { |
||
38 | await this.commandBus.execute(new RemoveUserCommand(id, user.id)); |
||
39 | } catch (e) { |
||
40 | throw new BadRequestException(e.message); |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 |