Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Fix but with no. of verified emails
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed May 30, 2019
1 parent ec166c5 commit d41ad09
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/rest/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,14 @@ export const deleteEmailFromUserForUser = async (
if (email.userId != userId)
throw new Error(ErrorCode.INSUFFICIENT_PERMISSION);
const verifiedEmails = await getUserVerifiedEmails(userId);
if (verifiedEmails.length > 1) {
const currentPrimaryEmailId = (await getUserPrimaryEmailObject(userId)).id;
if (currentPrimaryEmailId == emailId) {
const nextVerifiedEmail = verifiedEmails.filter(
emailObject => emailObject.id != emailId
)[0];
await updateUser(userId, { primaryEmail: nextVerifiedEmail });
}
} else {
if (verifiedEmails.length === 1 && email.isVerified)
throw new Error(ErrorCode.EMAIL_CANNOT_DELETE);
const currentPrimaryEmailId = (await getUserPrimaryEmailObject(userId)).id;
if (currentPrimaryEmailId == emailId) {
const nextVerifiedEmail = verifiedEmails.filter(
emailObject => emailObject.id != emailId
)[0];
await updateUser(userId, { primaryEmail: nextVerifiedEmail });
}
await deleteEmail(emailId);
await createEvent(
Expand Down

0 comments on commit d41ad09

Please sign in to comment.