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

Hotfix: Carl suggestion improvement #609

Merged
merged 5 commits into from
Nov 13, 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
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
Loading