Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 33 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
2 | import {Inject} from '@nestjs/common'; |
||
3 | import {GetProjectByIdQuery} from './GetProjectByIdQuery'; |
||
4 | import {IProjectRepository} from 'src/Domain/Project/Repository/IProjectRepository'; |
||
5 | import {ProjectView} from '../View/ProjectView'; |
||
6 | import {ProjectNotFoundException} from 'src/Domain/Project/Exception/ProjectNotFoundException'; |
||
7 | import {CustomerView} from 'src/Application/Customer/View/CustomerView'; |
||
8 | |||
9 | @QueryHandler(GetProjectByIdQuery) |
||
10 | export class GetProjectByIdQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('IProjectRepository') |
||
13 | private readonly projectRepository: IProjectRepository |
||
14 | ) {} |
||
15 | |||
16 | public async execute(query: GetProjectByIdQuery): Promise<ProjectView> { |
||
17 | const project = await this.projectRepository.findOneById(query.id); |
||
18 | if (!project) { |
||
19 | throw new ProjectNotFoundException(); |
||
20 | } |
||
21 | |||
22 | const customer = project.getCustomer(); |
||
23 | |||
24 | return new ProjectView( |
||
25 | project.getId(), |
||
26 | project.getName(), |
||
27 | project.getDayDuration(), |
||
28 | project.getInvoiceUnit(), |
||
29 | new CustomerView(customer.getId(), customer.getName()) |
||
30 | ); |
||
31 | } |
||
32 | } |
||
33 |