diff --git a/src/helpers/userHelper.js b/src/helpers/userHelper.js index af416f1a7..c75dd7b45 100644 --- a/src/helpers/userHelper.js +++ b/src/helpers/userHelper.js @@ -87,8 +87,18 @@ const userHelper = function () { firstName, lastName, infringement, - totalInfringements + totalInfringements, + timeRemaining ) { + let final_paragraph = ''; + + if (timeRemaining == undefined) { + final_paragraph = '

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.

'; + } else { + final_paragraph = `

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.

+

Reminder also that each blue square is removed from your profile 1 year after it was issued.

`; + } + const text = `Dear ${firstName} ${lastName},

Oops, it looks like something happened and you’ve managed to get a blue square.

Date Assigned: ${infringement.date}

@@ -96,9 +106,10 @@ const userHelper = function () {

Total Infringements: This is your ${moment .localeData() .ordinal(totalInfringements)} blue square of 5.

-

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.

+ ${final_paragraph}

Thank you,
One Community

`; + return text; }; @@ -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, @@ -356,6 +369,9 @@ const userHelper = function () { const timeNotMet = timeSpent < weeklycommittedHours; let description; + const timeRemaining = weeklycommittedHours - timeSpent; + + const updateResult = await userProfile.findByIdAndUpdate( personId, { @@ -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, "onecommunityglobal@gmail.com" );