| Total Complexity | 1 |
| Total Lines | 28 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import { Inject } from '@nestjs/common'; |
||
| 6 | |||
| 7 | @QueryHandler(GetYearlyLeavesSummaryQuery) |
||
| 8 | export class GetYearlyLeavesSummaryQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('ILeaveRepository') |
||
| 11 | private readonly leaveRepository: ILeaveRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute( |
||
| 15 | query: GetYearlyLeavesSummaryQuery |
||
| 16 | ): Promise<LeavesSummaryView[]> { |
||
| 17 | const yearlyLeavesSummaries = await this.leaveRepository.yearlyLeavesSummary( |
||
| 18 | 2023 |
||
| 19 | ); |
||
| 20 | |||
| 21 | const MAXIMUM_LEAVE_TIME_ALLOWED = 420 * 5 * 7; |
||
| 22 | |||
| 23 | const leavesSummaryViews = yearlyLeavesSummaries.map( |
||
| 24 | ({ total_time, first_name, last_name }) => |
||
| 25 | new LeavesSummaryView( |
||
| 26 | total_time, |
||
| 27 | MAXIMUM_LEAVE_TIME_ALLOWED - total_time, |
||
| 28 | first_name, |
||
| 29 | last_name |
||
| 30 | ) |
||
| 31 | ); |
||
| 32 | |||
| 33 | return leavesSummaryViews; |
||
| 34 | } |
||
| 36 |