src/Infrastructure/HumanResource/MealTicket/Controller/ListMealTicketsController.ts   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 42
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 37
mnd 1
bc 1
fnc 1
dl 0
loc 42
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A ListMealTicketsController.get 0 15 2
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