Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 49 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { GetInvoicesQuery } from './GetInvoicesQuery'; |
||
4 | import { Pagination } from 'src/Application/Common/Pagination'; |
||
5 | import { IInvoiceRepository } from 'src/Domain/Accounting/Repository/IInvoiceRepository'; |
||
6 | import { InvoiceView } from '../../View/DailyRate/InvoiceView'; |
||
7 | import { ProjectView } from 'src/Application/Project/View/ProjectView'; |
||
8 | import { CustomerView } from 'src/Application/Customer/View/CustomerView'; |
||
9 | |||
10 | @QueryHandler(GetInvoicesQuery) |
||
11 | export class GetInvoicesQueryHandler { |
||
12 | constructor( |
||
13 | @Inject('IInvoiceRepository') |
||
14 | private readonly invoiceRepository: IInvoiceRepository |
||
15 | ) {} |
||
16 | |||
17 | public async execute(query: GetInvoicesQuery): Promise<Pagination<InvoiceView>> { |
||
18 | const results: InvoiceView[] = []; |
||
19 | const [ invoices, total ] = await this.invoiceRepository.findInvoices( |
||
20 | query.page |
||
21 | ); |
||
22 | |||
23 | for (const invoice of invoices) { |
||
24 | const project = invoice.getProject(); |
||
25 | const customer = project.getCustomer(); |
||
26 | |||
27 | results.push( |
||
28 | new InvoiceView( |
||
29 | invoice.getId(), |
||
30 | invoice.getInvoiceId(), |
||
31 | invoice.getStatus(), |
||
32 | invoice.getCreatedAt(), |
||
33 | invoice.getExpiryDate(), |
||
34 | 100, |
||
35 | new ProjectView( |
||
36 | project.getId(), |
||
37 | project.getName(), |
||
38 | null, |
||
39 | null, |
||
40 | new CustomerView(customer.getId(), customer.getName()) |
||
41 | ) |
||
42 | ) |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | return new Pagination<InvoiceView>(results, total); |
||
47 | } |
||
48 | } |
||
49 |