Skip to content

Commit

Permalink
Merge pull request #616 from OneCommunityGlobal/Abdel_profile_setup_i…
Browse files Browse the repository at this point in the history
…nput_modal_fix

fix email sending for setup profile
  • Loading branch information
one-community authored Nov 19, 2023
2 parents fa2589d + 2fa5092 commit f0a1850
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
27 changes: 21 additions & 6 deletions src/controllers/profileInitialSetupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ function informManagerMessage(user) {
return message;
}

const sendEmailWithAcknowledgment = (email, subject, message) => {
return new Promise((resolve, reject) => {
emailSender(
email,
subject,
message,
null,
null,
null,
(error,result) => {
if (result) resolve(result)
if (error) reject(result)
}
);
});
};

const profileInitialSetupController = function (
ProfileInitialSetupToken,
userProfile,
Expand Down Expand Up @@ -114,15 +131,13 @@ const profileInitialSetupController = function (
const savedToken = await newToken.save();
const link = `${baseUrl}/ProfileInitialSetup/${savedToken.token}`;

emailSender(
const acknowledgment = await sendEmailWithAcknowledgment(
email,
"NEEDED: Complete your One Community profile setup",
sendLinkMessage(link),
null,
null
sendLinkMessage(link)
);

res.status(200).send(link);
res.status(200).send(acknowledgment);
}
} catch (error) {
res.status(400).send(`Error: ${error}`);
Expand Down
10 changes: 9 additions & 1 deletion src/utilities/emailSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const closure = () => {
if (!nextItem) return;

const {
recipient, subject, message, cc, bcc, replyTo,
recipient, subject, message, cc, bcc, replyTo, acknowledgingReceipt
} = nextItem;

try {
Expand All @@ -59,8 +59,14 @@ const closure = () => {
};

const result = await transporter.sendMail(mailOptions);
if (typeof acknowledgingReceipt === 'function') {
acknowledgingReceipt(null,result);
}
logger.logInfo(result);
} catch (error) {
if (typeof acknowledgingReceipt === 'function') {
acknowledgingReceipt(error,null);
}
logger.logException(error);
}
}, process.env.MAIL_QUEUE_INTERVAL || 1000);
Expand All @@ -72,6 +78,7 @@ const closure = () => {
cc = null,
bcc = null,
replyTo = null,
acknowledgingReceipt = null,
) {
if (process.env.sendEmail) {
queue.push({
Expand All @@ -81,6 +88,7 @@ const closure = () => {
cc,
bcc,
replyTo,
acknowledgingReceipt
});
}
};
Expand Down

0 comments on commit f0a1850

Please sign in to comment.