| Total Complexity | 3 |
| Complexity/F | 1.5 |
| Lines of Code | 55 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { |
||
| 2 | Body, |
||
| 3 | Post, |
||
| 4 | Controller, |
||
| 5 | Inject, |
||
| 6 | BadRequestException, |
||
| 7 | UseGuards, |
||
| 8 | Get, |
||
| 9 | Render, |
||
| 10 | Res |
||
| 11 | } from '@nestjs/common'; |
||
| 12 | import { Response } from 'express'; |
||
| 13 | import { ICommandBus } from 'src/Application/ICommandBus'; |
||
| 14 | import { MealTicketRemovalDTO } from '../DTO/MealTicketRemovalDTO'; |
||
| 15 | import { User } from 'src/Domain/HumanResource/User/User.entity'; |
||
| 16 | import { LoggedUser } from '../../User/Decorator/LoggedUser'; |
||
| 17 | import { CreateMealTicketRemovalCommand } from 'src/Application/HumanResource/MealTicket/Command/CreateMealTicketRemovalCommand'; |
||
| 18 | import { IsAuthenticatedGuard } from '../../User/Security/IsAuthenticatedGuard'; |
||
| 19 | import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName'; |
||
| 20 | import { RouteNameResolver } from 'src/Infrastructure/Common/ExtendedRouting/RouteNameResolver'; |
||
| 21 | |||
| 22 | @Controller('app/people/meal-tickets/removal/add') |
||
| 23 | @UseGuards(IsAuthenticatedGuard) |
||
| 24 | export class AddMealTicketRemovalController { |
||
| 25 | constructor( |
||
| 26 | @Inject('ICommandBus') |
||
| 27 | private readonly commandBus: ICommandBus, |
||
| 28 | private readonly resolver: RouteNameResolver |
||
| 29 | ) {} |
||
| 30 | |||
| 31 | @Get() |
||
| 32 | @WithName('people_meal_tickets_removal_add') |
||
| 33 | @Render('pages/meal_tickets/add.njk') |
||
| 34 | public async get() { |
||
| 35 | return {}; |
||
| 36 | } |
||
| 37 | |||
| 38 | @Post() |
||
| 39 | public async post( |
||
| 40 | @Body() { date }: MealTicketRemovalDTO, |
||
| 41 | @LoggedUser() user: User, |
||
| 42 | @Res() res: Response |
||
| 43 | ) { |
||
| 44 | try { |
||
| 45 | await this.commandBus.execute( |
||
| 46 | new CreateMealTicketRemovalCommand(date, user) |
||
| 47 | ); |
||
| 48 | |||
| 49 | res.redirect(303, this.resolver.resolve('people_meal_tickets_list')); |
||
| 50 | } catch (e) { |
||
| 51 | throw new BadRequestException(e.message); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 |