From 64963e6ab3c928e979c925be32b4a497500f0ced Mon Sep 17 00:00:00 2001 From: Gregory Pelletier Date: Mon, 15 Mar 2021 21:06:10 +0100 Subject: [PATCH] add await when saving data to be sure db is up to date when client will refresh --- .../FairCalendar/Command/AddEventCommandHandler.ts | 6 +++++- .../Leave/Converter/LeaveRequestToLeavesConverter.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/Application/FairCalendar/Command/AddEventCommandHandler.ts b/server/src/Application/FairCalendar/Command/AddEventCommandHandler.ts index 6f7cbb24..f25c5ae0 100644 --- a/server/src/Application/FairCalendar/Command/AddEventCommandHandler.ts +++ b/server/src/Application/FairCalendar/Command/AddEventCommandHandler.ts @@ -41,6 +41,8 @@ export class AddEventCommandHandler extends AbstractProjectAndTaskGetter { this.getTask(taskId) ]); + const savePromises: Promise[] = []; + for (const day of days) { const date = this.dateUtils.format(day, 'y-MM-dd'); const event = new Event( @@ -63,9 +65,11 @@ export class AddEventCommandHandler extends AbstractProjectAndTaskGetter { continue; } - this.eventRepository.save(event); + savePromises.push(this.eventRepository.save(event)); } + await Promise.all(savePromises); + return new AddEventsView(errors); } diff --git a/server/src/Domain/HumanResource/Leave/Converter/LeaveRequestToLeavesConverter.ts b/server/src/Domain/HumanResource/Leave/Converter/LeaveRequestToLeavesConverter.ts index eac61809..e7556723 100644 --- a/server/src/Domain/HumanResource/Leave/Converter/LeaveRequestToLeavesConverter.ts +++ b/server/src/Domain/HumanResource/Leave/Converter/LeaveRequestToLeavesConverter.ts @@ -46,7 +46,7 @@ export class LeaveRequestToLeavesConverter { ); } - this.leaveRepository.save(leaves); + await this.leaveRepository.save(leaves); } private getTime(