Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 47 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Delete, |
||
3 | Controller, |
||
4 | Inject, |
||
5 | BadRequestException, |
||
6 | UseGuards, |
||
7 | Param, |
||
8 | HttpCode |
||
9 | } from '@nestjs/common'; |
||
10 | import {AuthGuard} from '@nestjs/passport'; |
||
11 | import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
12 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
13 | import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser'; |
||
14 | import {User} from 'src/Domain/User/User.entity'; |
||
15 | import {DeleteActivityCommand} from 'src/Application/Activity/Command/DeleteActivityCommand'; |
||
16 | import {DeleteActivityDTO} from './DTO/DeleteActivityDTO'; |
||
17 | |||
18 | @Controller('activities') |
||
19 | @ApiUseTags('Activity') |
||
20 | @ApiBearerAuth() |
||
21 | @UseGuards(AuthGuard('bearer')) |
||
22 | export class DeleteActivityAction { |
||
23 | constructor( |
||
24 | @Inject('ICommandBus') |
||
25 | private readonly commandBus: ICommandBus |
||
26 | ) {} |
||
27 | |||
28 | @Delete(':id') |
||
29 | @ApiOperation({title: 'Delete activity'}) |
||
30 | @HttpCode(204) |
||
31 | public async index( |
||
32 | @Param() deleteActivityDto: DeleteActivityDTO, |
||
33 | @LoggedUser() user: User |
||
34 | ): Promise<boolean> { |
||
35 | try { |
||
36 | const {id: activityId} = deleteActivityDto; |
||
37 | await this.commandBus.execute( |
||
38 | new DeleteActivityCommand(user, activityId) |
||
39 | ); |
||
40 | |||
41 | return true; |
||
42 | } catch (e) { |
||
43 | throw new BadRequestException(e.message); |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 |