Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 40 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |