| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 38 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
| 2 | import {Inject} from '@nestjs/common'; |
||
| 3 | import {GetPaySlipByIdQuery} from './GetPaySlipByIdQuery'; |
||
| 4 | import {PaySlipView} from '../View/PaySlipView'; |
||
| 5 | import {IPaySlipRepository} from 'src/Domain/HumanResource/PaySlip/Repository/IPaySlipRepository'; |
||
| 6 | import {UserSummaryView} from '../../User/View/UserSummaryView'; |
||
| 7 | import {FileView} from 'src/Application/File/View/FileView'; |
||
| 8 | import {PaySlipNotFoundException} from 'src/Domain/HumanResource/PaySlip/Exception/PaySlipNotFoundException'; |
||
| 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 | ); |
||
| 36 | } |
||
| 37 | } |
||
| 38 |