Skip to content

Commit

Permalink
Merge pull request #485 from OneCommunityGlobal/shivansh_custom_blue_…
Browse files Browse the repository at this point in the history
…tick_email_for_core_team

Shivansh made Custom Infringement email for Core Team
  • Loading branch information
one-community authored Nov 11, 2023
2 parents 8c9eaf0 + e58d436 commit e9f78f3
Showing 1 changed file with 37 additions and 8 deletions.
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

0 comments on commit e9f78f3

Please sign in to comment.