src/Infrastructure/Customer/Controller/ListCustomersController.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 40
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A ListCustomersController.get 0 12 1
1
import {
2
  Controller,
3
  Inject,
4
  UseGuards,
5
  Get,
6
  Query,
7
  Render
8
} from '@nestjs/common';
9
import { IQueryBus } from 'src/Application/IQueryBus';
10
import { GetCustomersQuery } from 'src/Application/Customer/Query/GetCustomersQuery';
11
import { PaginationDTO } from 'src/Infrastructure/Common/DTO/PaginationDTO';
12
import { IsAuthenticatedGuard } from 'src/Infrastructure/HumanResource/User/Security/IsAuthenticatedGuard';
13
import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName';
14
import { Pagination } from 'src/Application/Common/Pagination';
15
import { CustomerView } from 'src/Application/Customer/View/CustomerView';
16
import { CustomerTableFactory } from '../Table/CustomerTableFactory';
17
18
@Controller('app/customers')
19
@UseGuards(IsAuthenticatedGuard)
20
export class ListCustomersController {
21
  constructor(
22
    @Inject('IQueryBus')
23
    private readonly queryBus: IQueryBus,
24
    private readonly tableFactory: CustomerTableFactory
25
  ) {}
26
27
  @Get()
28
  @WithName('crm_customers_list')
29
  @Render('pages/customers/list.njk')
30
  public async get(@Query() paginationDto: PaginationDTO) {
31
    const pagination: Pagination<CustomerView> = await this.queryBus.execute(
32
      new GetCustomersQuery(paginationDto.page)
33
    );
34
35
    const table = this.tableFactory.create(pagination.items);
36
37
    return { table, pagination, currentPage: paginationDto.page };
38
  }
39
}
40