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