Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix email sending for setup profile #616

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading