Skip to content

Commit

Permalink
Merge pull request #192 from fairnesscoop/fix/save-data-await
Browse files Browse the repository at this point in the history
Add await when saving data to be sure db is up to date when client will refresh ui
  • Loading branch information
ip512 authored Mar 16, 2021
2 parents 72e1526 + 64963e6 commit 5050b5b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class AddEventCommandHandler extends AbstractProjectAndTaskGetter {
this.getTask(taskId)
]);

const savePromises: Promise<any>[] = [];

for (const day of days) {
const date = this.dateUtils.format(day, 'y-MM-dd');
const event = new Event(
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class LeaveRequestToLeavesConverter {
);
}

this.leaveRepository.save(leaves);
await this.leaveRepository.save(leaves);
}

private getTime(
Expand Down

0 comments on commit 5050b5b

Please sign in to comment.