Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 42 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Controller, |
||
3 | Inject, |
||
4 | UseGuards, |
||
5 | Get, |
||
6 | Render, |
||
7 | BadRequestException |
||
8 | } from '@nestjs/common'; |
||
9 | import { IQueryBus } from 'src/Application/IQueryBus'; |
||
10 | import { IsAuthenticatedGuard } from 'src/Infrastructure/HumanResource/User/Security/IsAuthenticatedGuard'; |
||
11 | import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName'; |
||
12 | import { GetMealTicketsPerMonthQuery } from 'src/Application/HumanResource/MealTicket/Query/GetMealTicketsPerMonthQuery'; |
||
13 | import { MealTicketsPerMonthView } from 'src/Application/HumanResource/MealTicket/Views/MealTicketsPerMonthView'; |
||
14 | import { MealTicketTableFactory } from '../Table/MealTicketTableFactory'; |
||
15 | |||
16 | @Controller('app/people/meal_tickets') |
||
17 | @UseGuards(IsAuthenticatedGuard) |
||
18 | export class ListMealTicketsController { |
||
19 | constructor( |
||
20 | @Inject('IQueryBus') |
||
21 | private readonly queryBus: IQueryBus, |
||
22 | private readonly tableFactory: MealTicketTableFactory |
||
23 | ) {} |
||
24 | |||
25 | @Get() |
||
26 | @WithName('people_meal_tickets_list') |
||
27 | @Render('pages/meal_tickets/list.njk') |
||
28 | public async get() { |
||
29 | try { |
||
30 | const mealTickets: MealTicketsPerMonthView[] = await this.queryBus.execute( |
||
31 | new GetMealTicketsPerMonthQuery(new Date()) |
||
32 | ); |
||
33 | |||
34 | const table = this.tableFactory.create(mealTickets); |
||
35 | |||
36 | return { table }; |
||
37 | } catch (e) { |
||
38 | throw new BadRequestException(e.message); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 |