import { Inject } from '@nestjs/common' ; import { CommandHandler } from '@nestjs/cqrs' ; import { ILeaveRequestRepository } from 'src/Domain/HumanResource/Leave/Repository/ILeaveRequestRepository' ; import { UpdateLeaveRequestCommand } from './UpdateLeaveRequestCommand' ; import { LeaveRequestNotFoundException } from 'src/Domain/HumanResource/Leave/Exception/LeaveRequestNotFoundException' ; @ CommandHandler ( UpdateLeaveRequestCommand ) export class UpdateLeaveRequestCommandHandler { constructor ( @ Inject ( 'ILeaveRequestRepository' ) private readonly leaveRequestRepository ) { } public async execute ( command ) { const { id , type , startDate , startsAllDay , endDate , endsAllDay , comment } = command ; const leaveRequest = await this . leaveRequestRepository . findOneById ( id ) ; if ( ! leaveRequest ) { throw new LeaveRequestNotFoundException ( ) ; } leaveRequest . update ( type , startDate , startsAllDay , endDate , endsAllDay , comment ) ; await this . leaveRequestRepository . save ( leaveRequest ) ; return leaveRequest . getId ( ) ; } }