Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 32 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
2 | import { QueryHandler } from '@nestjs/cqrs'; |
||
3 | import { GetCustomersQuery } from './GetCustomersQuery'; |
||
4 | import { CustomerView } from '../View/CustomerView'; |
||
5 | import { ICustomerRepository } from 'src/Domain/Customer/Repository/ICustomerRepository'; |
||
6 | import { Pagination } from 'src/Application/Common/Pagination'; |
||
7 | |||
8 | @QueryHandler(GetCustomersQuery) |
||
9 | export class GetCustomersQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('ICustomerRepository') |
||
12 | private readonly customerRepository: ICustomerRepository |
||
13 | ) {} |
||
14 | |||
15 | public async execute( |
||
16 | query: GetCustomersQuery |
||
17 | ): Promise<Pagination<CustomerView>> { |
||
18 | const customerViews: CustomerView[] = []; |
||
19 | const [customers, total] = await this.customerRepository.findCustomers( |
||
20 | query.page |
||
21 | ); |
||
22 | |||
23 | for (const customer of customers) { |
||
24 | customerViews.push( |
||
25 | new CustomerView(customer.getId(), customer.getName()) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | return new Pagination<CustomerView>(customerViews, total); |
||
30 | } |
||
31 | } |
||
32 |