| Total Complexity | 4 | 
| Total Lines | 47 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import {QueryHandler} from '@nestjs/cqrs'; | 
            ||
| 8 | |||
| 9 | @QueryHandler(GetHolidaysQuery)  | 
            ||
| 10 | export class GetHolidaysQueryHandler { | 
            ||
| 11 | constructor(  | 
            ||
| 12 |     @Inject('IHolidayRepository') | 
            ||
| 13 | private readonly holidayRepository: IHolidayRepository,  | 
            ||
| 14 |     @Inject('IDateUtils') | 
            ||
| 15 | private readonly dateUtils: IDateUtils  | 
            ||
| 16 |   ) {} | 
            ||
| 17 | |||
| 18 |   public async execute(query: GetHolidaysQuery): Promise<HolidayView[]> { | 
            ||
| 19 | const holidays = await this.holidayRepository.findHolidays();  | 
            ||
| 20 | const holidayViews: HolidayView[] = [];  | 
            ||
| 21 | |||
| 22 |     for (const holiday of holidays) { | 
            ||
| 23 | const user = holiday.getUser();  | 
            ||
| 24 | let duration = this.dateUtils.getWorkedDaysDuringAPeriod(  | 
            ||
| 25 | new Date(holiday.getStartDate()),  | 
            ||
| 26 | new Date(holiday.getEndDate())  | 
            ||
| 27 | ).length;  | 
            ||
| 28 | |||
| 29 |       if (false === holiday.isStartsAllDay()) { | 
            ||
| 30 | duration -= 0.5;  | 
            ||
| 31 | }  | 
            ||
| 32 | |||
| 33 |       if (false === holiday.isEndsAllDay()) { | 
            ||
| 34 | duration -= 0.5;  | 
            ||
| 35 | }  | 
            ||
| 36 | |||
| 37 | holidayViews.push(  | 
            ||
| 38 | new HolidayView(  | 
            ||
| 39 | holiday.getId(),  | 
            ||
| 40 | holiday.getLeaveType(),  | 
            ||
| 41 | holiday.getStatus(),  | 
            ||
| 42 | holiday.getStartDate(),  | 
            ||
| 43 | holiday.getEndDate(),  | 
            ||
| 44 | duration,  | 
            ||
| 45 | new UserSummaryView(  | 
            ||
| 46 | user.getId(),  | 
            ||
| 47 | user.getFirstName(),  | 
            ||
| 48 | user.getLastName()  | 
            ||
| 49 | )  | 
            ||
| 50 | )  | 
            ||
| 51 | );  | 
            ||
| 52 | }  | 
            ||
| 53 | |||
| 54 | return holidayViews;  | 
            ||
| 55 | }  | 
            ||
| 57 |