| Total Complexity | 2 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 18 | |||
| 19 | @Controller('holidays') |
||
| 20 | @ApiUseTags('Human Resource') |
||
| 21 | @ApiBearerAuth() |
||
| 22 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 23 | export class CreateHolidayAction { |
||
| 24 | constructor( |
||
| 25 | @Inject('ICommandBus') |
||
| 26 | private readonly commandBus: ICommandBus |
||
| 27 | ) {} |
||
| 28 | |||
| 29 | @Post() |
||
| 30 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
| 31 | @ApiOperation({title: 'Create new holiday'}) |
||
| 32 | public async index(@Body() dto: HolidayDTO, @LoggedUser() user: User) { |
||
| 33 | const { |
||
| 34 | leaveType, |
||
| 35 | startDate, |
||
| 36 | startsAllDay, |
||
| 37 | endDate, |
||
| 38 | endsAllDay, |
||
| 39 | comment |
||
| 40 | } = dto; |
||
| 41 | |||
| 42 | try { |
||
| 43 | const id = await this.commandBus.execute( |
||
| 44 | new CreateHolidayCommand( |
||
| 45 | user, |
||
| 46 | leaveType, |
||
| 47 | startDate, |
||
| 48 | Boolean(startsAllDay), |
||
| 49 | endDate, |
||
| 50 | Boolean(endsAllDay), |
||
| 51 | comment |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | |||
| 55 | return {id}; |
||
| 56 | } catch (e) { |
||
| 57 | throw new BadRequestException(e.message); |
||
| 58 | } |
||
| 61 |