| Total Complexity | 3 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {Inject} from '@nestjs/common'; |
||
| 9 | |||
| 10 | @CommandHandler(RefuseHolidayCommand) |
||
| 11 | export class RefuseHolidayCommandHandler { |
||
| 12 | constructor( |
||
| 13 | @Inject('IHolidayRepository') |
||
| 14 | private readonly holidayRepository: IHolidayRepository, |
||
| 15 | @Inject('IDateUtils') |
||
| 16 | private readonly dateUtils: IDateUtils, |
||
| 17 | private readonly canHolidayBeRefused: CanHolidayBeRefused |
||
| 18 | ) {} |
||
| 19 | |||
| 20 | public async execute(command: RefuseHolidayCommand): Promise<string> { |
||
| 21 | const {user, id} = command; |
||
| 22 | |||
| 23 | const holiday = await this.holidayRepository.findOneById(id); |
||
| 24 | if (!holiday) { |
||
| 25 | throw new HolidayNotFoundException(); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (false === this.canHolidayBeRefused.isSatisfiedBy(holiday, user)) { |
||
| 29 | throw new HolidayCantBeRefusedException(); |
||
| 30 | } |
||
| 31 | |||
| 32 | holiday.refuse(user, this.dateUtils.getCurrentDate().toISOString()); |
||
| 33 | await this.holidayRepository.save(holiday); |
||
| 34 | |||
| 35 | return holiday.getId(); |
||
| 36 | } |
||
| 38 |