| Total Complexity | 2 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {Inject} from '@nestjs/common'; |
||
| 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.getOriginalName(), file.getSize()) |
||
| 34 | ) |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | |||
| 38 | return payStubViews; |
||
| 39 | } |
||
| 41 |