Skip to content

Commit

Permalink
Send mails in serial
Browse files Browse the repository at this point in the history
  • Loading branch information
VisenP committed Jan 17, 2024
1 parent cba7c40 commit 68c3ad9
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions apps/backend/src/routes/notifications/NotificationsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,25 @@ NotificationsHandler.post(
preferencesByUserId[preference.user_id.toString()] = preference;
}

await Promise.all(
users.map((user) => {
// eslint-disable-next-line no-async-promise-executor
new Promise<void>(async (resolve) => {
for (const user of users) {
const preference = preferencesByUserId[user.user_id.toString()];

if (preference.status === "none") return Promise.resolve();
if (preference.status === "none") return;

if (preference.status === "contest-only" && !req.body.contestAnnouncement)
return Promise.resolve();
if (preference.status === "contest-only" && !req.body.contestAnnouncement) return;

return sendMail(
await sendMail(
user,
req.body.subject,
req.body.text,
preference,
req.body.debugMode
);
})
);
}
resolve();
});

return respond(res, StatusCodes.OK);
}
Expand Down

0 comments on commit 68c3ad9

Please sign in to comment.