Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 39 |
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 {DeleteEventCommand} from 'src/Application/FairCalendar/Command/DeleteEventCommand'; |
||
16 | import {DeleteEventDTO} from './DTO/DeleteEventDTO'; |
||
17 | |||
18 | @Controller('events') |
||
19 | @ApiUseTags('Event') |
||
20 | @ApiBearerAuth() |
||
21 | @UseGuards(AuthGuard('bearer')) |
||
22 | export class DeleteEventAction { |
||
23 | constructor( |
||
24 | @Inject('ICommandBus') |
||
25 | private readonly commandBus: ICommandBus |
||
26 | ) {} |
||
27 | |||
28 | @Delete(':id') |
||
29 | @ApiOperation({title: 'Delete an event'}) |
||
30 | @HttpCode(204) |
||
31 | public async index(@Param() dto: DeleteEventDTO, @LoggedUser() user: User) { |
||
32 | try { |
||
33 | await this.commandBus.execute(new DeleteEventCommand(dto.id, user)); |
||
34 | } catch (e) { |
||
35 | throw new BadRequestException(e.message); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 |