Skip to content

Commit

Permalink
Updated delete in syncMailingList and sync assignApplicationStatus (#139
Browse files Browse the repository at this point in the history
)

* Updated delete in syncMailingList and sync assignApplicationStatus

- delete Promise.all was changed to Promise.allSettled
- if user is not found, an error is not thrown
- only syncing the mailing list if legit is true

* Fixed delete error logic

* Removed legit
  • Loading branch information
Lindsay-X authored and Frederic Pun committed Jul 17, 2024
1 parent 09bf929 commit f247c68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/controller/applicationStatus/assignApplicationStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ export default async (legit?: boolean, waitlistOver?: boolean, rawAcceptedFromWa
}
}


await syncMailingLists(undefined, true);

return { dead, accepted, rejected, waitlisted };
};
5 changes: 3 additions & 2 deletions src/services/mailer/syncMailingList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ export default async (mailingListID: string, emails: string[], forceUpdate?: boo
// Step 3: Delete users that are on the list that shouldn't be
const toBeDeleted = [...beforeSubscribers].filter(x => !expctedAfterSubscribers.has(x) && x);

const deleteOldResults = await Promise.all(toBeDeleted.map(
const deleteOldResults = await Promise.allSettled(toBeDeleted.map(
(userEmail: string) => deleteSubscriptionRequest(mailingListID, userEmail),
));

for (const result of deleteOldResults) {
if (result.status != 200 || !result.data) {
if ((result.status === 'fulfilled' && !result.value)
|| (result.status === 'rejected' && result.reason != 'failed to fetch') ) {
throw new InternalServerError('Unable to delete subscriber');
}
}
Expand Down

0 comments on commit f247c68

Please sign in to comment.