Skip to content

Commit

Permalink
Merge pull request #609 from OneCommunityGlobal/Carl-Suggestion-Impro…
Browse files Browse the repository at this point in the history
…vement

Hotfix: Carl suggestion improvement
  • Loading branch information
one-community authored Nov 13, 2023
2 parents e9f78f3 + db3a870 commit fa2589d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
39 changes: 25 additions & 14 deletions src/controllers/dashBoardController.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require("mongoose");
const path = require("path");
const fs = require("fs/promises");
const mongoose = require("mongoose");
const dashboardhelper = require("../helpers/dashboardhelper")();
const emailSender = require("../utilities/emailSender");

Expand Down Expand Up @@ -168,34 +168,45 @@ const dashboardcontroller = function () {
<p>${args[3][item]}</p>`
);
}
const text = `New Suggestion:
<p>Suggestion Category:</p>
<p>${args[0]}</p>
<p>Suggestion:</p>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
<p>Wants Feedback:</p>
<p>${args[2]}</p>
<p>Thank you,<br />
One Community</p>`;
const text = `New Suggestion From <b>${args[3].firstName} ${
args[3].lastName
}
</b>:
<b> &#9913; Suggestion Category:</b>
<p>${args[0]}</p>
<b> &#9913; Suggestion:</b>
<p>${args[1]}</p>
${fieldaaray.length > 0 ? fieldaaray : ""}
<b> &#9913; Name of Suggester:</b>
<p>${args[3].firstName} ${args[3].lastName}</p>
<b> &#9913; Email of Suggester:</b>
<p>${args[4]}</p>
<b> &#9913; Wants Feedback:</b>
<p>${args[2]}</p>
<b>Thank you,<br />
One Community</b>`;

return text;
};

// send suggestion email
const sendMakeSuggestion = async (req, res) => {
const { suggestioncate, suggestion, confirm, ...rest } = req.body;
const { suggestioncate, suggestion, confirm, email, ...rest } = req.body;
const emailBody = await getsuggestionEmailBody(
suggestioncate,
suggestion,
confirm,
rest
rest,
email
);
try {
emailSender(
"[email protected]",
"A new suggestion",
emailBody
emailBody,
null,
null,
email
);
res.status(200).send("Success");
} catch {
Expand Down
22 changes: 17 additions & 5 deletions src/utilities/emailSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const nodemailer = require('nodemailer');
const { google } = require('googleapis');
const logger = require('../startup/logger');


const closure = () => {
const queue = [];

Expand Down Expand Up @@ -36,8 +35,8 @@ const closure = () => {
if (!nextItem) return;

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

try {
// Generate the accessToken on the fly
Expand All @@ -51,6 +50,7 @@ const closure = () => {
bcc,
subject,
html: message,
replyTo,
auth: {
user: CLIENT_EMAIL,
refreshToken: REFRESH_TOKEN,
Expand All @@ -65,10 +65,22 @@ const closure = () => {
}
}, process.env.MAIL_QUEUE_INTERVAL || 1000);

const emailSender = function (recipient, subject, message, cc = null, bcc = null) {
const emailSender = function (
recipient,
subject,
message,
cc = null,
bcc = null,
replyTo = null,
) {
if (process.env.sendEmail) {
queue.push({
recipient, subject, message, cc, bcc,
recipient,
subject,
message,
cc,
bcc,
replyTo,
});
}
};
Expand Down

0 comments on commit fa2589d

Please sign in to comment.