Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 44 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
2 | import {Inject} from '@nestjs/common'; |
||
3 | import {GetProjectsQuery} from './GetProjectsQuery'; |
||
4 | import {ProjectView} from '../View/ProjectView'; |
||
5 | import {IProjectRepository} from 'src/Domain/Project/Repository/IProjectRepository'; |
||
6 | import {CustomerView} from 'src/Application/Customer/View/CustomerView'; |
||
7 | import {Pagination} from 'src/Application/Common/Pagination'; |
||
8 | |||
9 | @QueryHandler(GetProjectsQuery) |
||
10 | export class GetProjectsQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('IProjectRepository') |
||
13 | private readonly projectRepository: IProjectRepository |
||
14 | ) {} |
||
15 | |||
16 | public async execute( |
||
17 | query: GetProjectsQuery |
||
18 | ): Promise<Pagination<ProjectView>> { |
||
19 | const {customerId, page} = query; |
||
20 | |||
21 | const projectViews: ProjectView[] = []; |
||
22 | const [projects, total] = await this.projectRepository.findProjects( |
||
23 | page, |
||
24 | customerId |
||
25 | ); |
||
26 | |||
27 | for (const project of projects) { |
||
28 | const customer = project.getCustomer(); |
||
29 | |||
30 | projectViews.push( |
||
31 | new ProjectView( |
||
32 | project.getId(), |
||
33 | project.getName(), |
||
34 | project.getDayDuration(), |
||
35 | project.getInvoiceUnit(), |
||
36 | new CustomerView(customer.getId(), customer.getName()) |
||
37 | ) |
||
38 | ); |
||
39 | } |
||
40 | |||
41 | return new Pagination<ProjectView>(projectViews, total); |
||
42 | } |
||
43 | } |
||
44 |