Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 44 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Controller, |
||
3 | Inject, |
||
4 | BadRequestException, |
||
5 | UseGuards, |
||
6 | Param, |
||
7 | Put |
||
8 | } from '@nestjs/common'; |
||
9 | import {AuthGuard} from '@nestjs/passport'; |
||
10 | import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
11 | import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
12 | import {Roles} from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
13 | import {UserRole, User} from 'src/Domain/HumanResource/User/User.entity'; |
||
14 | import {RolesGuard} from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
15 | import {RefuseHolidayCommand} from 'src/Application/HumanResource/Holiday/Command/RefuseHolidayCommand'; |
||
16 | import {LoggedUser} from '../../User/Decorator/LoggedUser'; |
||
17 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
18 | |||
19 | @Controller('holidays') |
||
20 | @ApiUseTags('Human Resource') |
||
21 | @ApiBearerAuth() |
||
22 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
23 | export class RefuseHolidayAction { |
||
24 | constructor( |
||
25 | @Inject('ICommandBus') |
||
26 | private readonly commandBus: ICommandBus |
||
27 | ) {} |
||
28 | |||
29 | @Put(':id/refuse') |
||
30 | @Roles(UserRole.COOPERATOR) |
||
31 | @ApiOperation({title: 'Refuse holiday'}) |
||
32 | public async index(@Param() dto: IdDTO, @LoggedUser() user: User) { |
||
33 | try { |
||
34 | const id = await this.commandBus.execute( |
||
35 | new RefuseHolidayCommand(user, dto.id) |
||
36 | ); |
||
37 | |||
38 | return {id}; |
||
39 | } catch (e) { |
||
40 | throw new BadRequestException(e.message); |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 |