Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 41 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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 |