Passed
Pull Request — master (#103)
by Mathieu
01:32
created

server/src/Application/HumanResource/PayStub/Query/GetPayStubsQueryHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 41
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetPayStubsQueryHandler.execute 0 24 2
1
import {Inject} from '@nestjs/common';
2
import {QueryHandler} from '@nestjs/cqrs';
3
import {GetPayStubsQuery} from './GetPayStubsQuery';
4
import {IPayStubRepository} from 'src/Domain/HumanResource/PayStub/Repository/IPayStubRepository';
5
import {PayStubView} from '../View/PayStubView';
6
import {UserSummaryView} from '../../User/View/UserSummaryView';
7
import {FileView} from 'src/Application/File/View/FileView';
8
9
@QueryHandler(GetPayStubsQuery)
10
export class GetPayStubsQueryHandler {
11
  constructor(
12
    @Inject('IPayStubRepository')
13
    private readonly payStubRepository: IPayStubRepository
14
  ) {}
15
16
  public async execute(query: GetPayStubsQuery): Promise<PayStubView[]> {
17
    const payStubs = await this.payStubRepository.findAll();
18
    const payStubViews: PayStubView[] = [];
19
20
    for (const payStub of payStubs) {
21
      const user = payStub.getUser();
22
      const file = payStub.getFile();
23
24
      payStubViews.push(
25
        new PayStubView(
26
          payStub.getId(),
27
          payStub.getDate(),
28
          new UserSummaryView(
29
            user.getId(),
30
            user.getFirstName(),
31
            user.getLastName()
32
          ),
33
          new FileView(file.getId(), file.getName(), file.getSize())
34
        )
35
      );
36
    }
37
38
    return payStubViews;
39
  }
40
}
41