| Total Complexity | 2 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
| 9 | |||
| 10 | @QueryHandler(GetPaySlipByIdQuery) |
||
| 11 | export class GetPaySlipByIdQueryHandler { |
||
| 12 | constructor( |
||
| 13 | @Inject('IPaySlipRepository') |
||
| 14 | private readonly payslipRepository: IPaySlipRepository |
||
| 15 | ) {} |
||
| 16 | |||
| 17 | public async execute(query: GetPaySlipByIdQuery): Promise<PaySlipView> { |
||
| 18 | const paySlip = await this.payslipRepository.findOneById(query.id); |
||
| 19 | if (!paySlip) { |
||
| 20 | throw new PaySlipNotFoundException(); |
||
| 21 | } |
||
| 22 | |||
| 23 | const user = paySlip.getUser(); |
||
| 24 | const file = paySlip.getFile(); |
||
| 25 | |||
| 26 | return new PaySlipView( |
||
| 27 | paySlip.getId(), |
||
| 28 | paySlip.getDate(), |
||
| 29 | new UserSummaryView( |
||
| 30 | user.getId(), |
||
| 31 | user.getFirstName(), |
||
| 32 | user.getLastName() |
||
| 33 | ), |
||
| 34 | new FileView(file.getId(), file.getOriginalName(), file.getSize()) |
||
| 35 | ); |
||
| 38 |