Skip to content

Commit

Permalink
Merge branch 'development' into gary_add_materials_page
Browse files Browse the repository at this point in the history
  • Loading branch information
tdkent committed Nov 16, 2023
2 parents cec78db + fa2589d commit 772c720
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/controllers/badgeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const mongoose = require('mongoose');
const UserProfile = require('../models/userProfile');
const { hasPermission } = require('../utilities/permissions');
const escapeRegex = require('../utilities/escapeRegex');
const cache = require('../utilities/nodeCache')();

const badgeController = function (Badge) {
const getAllBadges = async function (req, res) {
Expand Down Expand Up @@ -47,6 +48,8 @@ const badgeController = function (Badge) {
if (result) {
record.badgeCollection = req.body.badgeCollection;

if (cache.hasCache(`user-${userToBeAssigned}`)) cache.removeCache(`user-${userToBeAssigned}`);

record.save()
.then(results => res.status(201).send(results._id))
.catch(errors => res.status(500).send(errors));
Expand Down
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
45 changes: 37 additions & 8 deletions src/helpers/userHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,29 @@ const userHelper = function () {
firstName,
lastName,
infringement,
totalInfringements
totalInfringements,
timeRemaining
) {
let final_paragraph = '';

if (timeRemaining == undefined) {
final_paragraph = '<p>Life happens and we understand that. That’s why we allow 5 of them before taking action. This action usually includes removal from our team though, so please let your direct supervisor know what happened and do your best to avoid future blue squares if you are getting close to 5 and wish to avoid termination. Each blue square drops off after a year.</p>';
} else {
final_paragraph = `<p>Life happens and we understand that. Please make up the missed hours this following week though to avoid getting another blue square. So you know what’s needed, the missing/incomplete hours (${timeRemaining} hours) have been added to your current week and this new weekly total can be seen at the top of your dashboard.</p>
<p>Reminder also that each blue square is removed from your profile 1 year after it was issued.</p>`;
}

const text = `Dear <b>${firstName} ${lastName}</b>,
<p>Oops, it looks like something happened and you’ve managed to get a blue square.</p>
<p><b>Date Assigned:</b> ${infringement.date}</p>
<p><b>Description:</b> ${infringement.description}</p>
<p><b>Total Infringements:</b> This is your <b>${moment
.localeData()
.ordinal(totalInfringements)}</b> blue square of 5.</p>
<p>Life happens and we understand that. That’s why we allow 5 of them before taking action. This action usually includes removal from our team though, so please let your direct supervisor know what happened and do your best to avoid future blue squares if you are getting close to 5 and wish to avoid termination. Each blue square drops off after a year.</p>
${final_paragraph}
<p>Thank you,<br />
One Community</p>`;

return text;
};

Expand Down Expand Up @@ -322,6 +333,8 @@ const userHelper = function () {
for (let i = 0; i < users.length; i += 1) {
const user = users[i];

const person = await userProfile.findById(user._id);

const foundReason = await Reason.findOne({
date: currentUTCDate,
userId: user._id,
Expand Down Expand Up @@ -356,6 +369,9 @@ const userHelper = function () {
const timeNotMet = timeSpent < weeklycommittedHours;
let description;

const timeRemaining = weeklycommittedHours - timeSpent;


const updateResult = await userProfile.findByIdAndUpdate(
personId,
{
Expand Down Expand Up @@ -446,15 +462,28 @@ const userHelper = function () {
{ new: true }
);

emailSender(
status.email,
"New Infringement Assigned",
getInfringementEmailBody(
let emailBody = '';
if (person.role == 'Core Team' && timeRemaining > 0) {
emailBody = getInfringementEmailBody(
status.firstName,
status.lastName,
infringement,
status.infringements.length
),
status.infringements.length,
timeRemaining,
);
} else {
emailBody = getInfringementEmailBody(
status.firstName,
status.lastName,
infringement,
status.infringements.length,
);
}

emailSender(
status.email,
'New Infringement Assigned',
emailBody,
null,
"[email protected]"
);
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 772c720

Please sign in to comment.