From a56b80d8bd5ae4c2ca49a32ab730e26ea84e2938 Mon Sep 17 00:00:00 2001 From: Shivansh Sharma Date: Thu, 24 Aug 2023 18:20:23 -0700 Subject: [PATCH] Changes made in getInfringementEmailBody function --- src/helpers/userHelper.js | 45 +++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/helpers/userHelper.js b/src/helpers/userHelper.js index f9428b3a1..e1898f334 100644 --- a/src/helpers/userHelper.js +++ b/src/helpers/userHelper.js @@ -85,17 +85,28 @@ const userHelper = function () { lastName, infringement, 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}

Description: ${infringement.description}

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.

+ .localeData() + .ordinal(totalInfringements)} blue square of 5.

+ ${final_paragraph}

Thank you,
One Community

`; + return text; }; @@ -299,7 +310,7 @@ const userHelper = function () { for (let i = 0; i < users.length; i += 1) { const user = users[i]; - + const person = await userProfile.findById(user._id); const personId = mongoose.Types.ObjectId(user._id); let hasWeeklySummary = false; @@ -327,6 +338,9 @@ const userHelper = function () { const timeNotMet = timeSpent < weeklycommittedHours; let description; + const timeRemaining = weeklycommittedHours - timeSpent; + + const updateResult = await userProfile.findByIdAndUpdate( personId, { @@ -409,15 +423,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, + timeRemaining, + ); + } else { + emailBody = getInfringementEmailBody( status.firstName, status.lastName, infringement, status.infringements.length, - ), + ); + } + + emailSender( + status.email, + 'New Infringement Assigned', + emailBody, null, 'onecommunityglobal@gmail.com', );