Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 47 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Body, |
||
3 | Post, |
||
4 | Controller, |
||
5 | Inject, |
||
6 | BadRequestException, |
||
7 | UseGuards |
||
8 | } from '@nestjs/common'; |
||
9 | import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; |
||
10 | import { AuthGuard } from '@nestjs/passport'; |
||
11 | import { ICommandBus } from 'src/Application/ICommandBus'; |
||
12 | import { MealTicketRemovalDTO } from '../DTO/MealTicketRemovalDTO'; |
||
13 | import { User, UserRole } from 'src/Domain/HumanResource/User/User.entity'; |
||
14 | import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
15 | import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
16 | import { LoggedUser } from '../../User/Decorator/LoggedUser'; |
||
17 | import { CreateMealTicketRemovalCommand } from 'src/Application/HumanResource/MealTicket/Command/CreateMealTicketRemovalCommand'; |
||
18 | |||
19 | @Controller('meal-tickets-removals') |
||
20 | @ApiTags('Human Resource') |
||
21 | @ApiBearerAuth() |
||
22 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
23 | export class CreateMealTicketRemovalAction { |
||
24 | constructor( |
||
25 | @Inject('ICommandBus') |
||
26 | private readonly commandBus: ICommandBus |
||
27 | ) {} |
||
28 | |||
29 | @Post() |
||
30 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
31 | @ApiOperation({ summary: 'Create new meal ticket removal' }) |
||
32 | public async index( |
||
33 | @Body() { date, comment }: MealTicketRemovalDTO, |
||
34 | @LoggedUser() user: User |
||
35 | ) { |
||
36 | try { |
||
37 | const id = await this.commandBus.execute( |
||
38 | new CreateMealTicketRemovalCommand(date, comment, user) |
||
39 | ); |
||
40 | |||
41 | return { id }; |
||
42 | } catch (e) { |
||
43 | throw new BadRequestException(e.message); |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 |