Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 42 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | BadRequestException, |
||
3 | Controller, |
||
4 | Inject, |
||
5 | Param, |
||
6 | Post, |
||
7 | Res, |
||
8 | UseGuards |
||
9 | } from '@nestjs/common'; |
||
10 | import { Response } from 'express'; |
||
11 | import { ICommandBus } from 'src/Application/ICommandBus'; |
||
12 | import { IsAuthenticatedGuard } from 'src/Infrastructure/HumanResource/User/Security/IsAuthenticatedGuard'; |
||
13 | import { LoggedUser } from 'src/Infrastructure/HumanResource/User/Decorator/LoggedUser'; |
||
14 | import { User } from 'src/Domain/HumanResource/User/User.entity'; |
||
15 | import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
16 | import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName'; |
||
17 | import { DeleteEventCommand } from 'src/Application/FairCalendar/Command/DeleteEventCommand'; |
||
18 | |||
19 | @Controller('app/faircalendar/events/delete') |
||
20 | @UseGuards(IsAuthenticatedGuard) |
||
21 | export class DeleteEventController { |
||
22 | constructor( |
||
23 | @Inject('ICommandBus') |
||
24 | private readonly commandBus: ICommandBus |
||
25 | ) {} |
||
26 | |||
27 | @Post(':id') |
||
28 | @WithName('faircalendar_event_delete') |
||
29 | public async post( |
||
30 | @Param() dto: IdDTO, |
||
31 | @LoggedUser() user: User, |
||
32 | @Res() res: Response |
||
33 | ) { |
||
34 | try { |
||
35 | await this.commandBus.execute(new DeleteEventCommand(dto.id, user)); |
||
36 | res.redirect(303, '/app/faircalendar'); |
||
37 | } catch (e) { |
||
38 | throw new BadRequestException(e.message); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |