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