Passed
Pull Request — master (#188)
by Mathieu
02:03
created

server/src/Application/Project/Query/GetProjectByIdQueryHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 33
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetProjectByIdQueryHandler.execute 0 15 2
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