From b6d8cf4e03ae4f7edc7fe33ae1300e00f1dd001d Mon Sep 17 00:00:00 2001 From: 20chen-7 Date: Thu, 15 Aug 2024 09:49:43 -0600 Subject: [PATCH] chore: set-final-day --- src/controllers/userProfileController.js | 1 + src/helpers/userHelper.js | 31 ++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/controllers/userProfileController.js b/src/controllers/userProfileController.js index a61cf3c43..fff2df579 100644 --- a/src/controllers/userProfileController.js +++ b/src/controllers/userProfileController.js @@ -1207,6 +1207,7 @@ const userProfileController = function (UserProfile, Project) { endDate, user.email, recipients, + isSet, ); auditIfProtectedAccountUpdated( req.body.requestor.requestorId, diff --git a/src/helpers/userHelper.js b/src/helpers/userHelper.js index 4fbe3376e..ed9c52131 100644 --- a/src/helpers/userHelper.js +++ b/src/helpers/userHelper.js @@ -2030,9 +2030,16 @@ const userHelper = function () { }); }; - const sendDeactivateEmailBody = function (firstName, lastName, endDate, email, recipients) { - if (endDate) { - const subject = `IMPORTANT:${firstName} ${lastName} has been deactivated in the Highest Good Network`; + const sendDeactivateEmailBody = function ( + firstName, + lastName, + endDate, + email, + recipients, + isSet, + ) { + if (endDate && !isSet) { + const subject = `IMPORTANT: ${firstName} ${lastName} has been deactivated in the Highest Good Network`; const emailBody = `

Management,

Please note that ${firstName} ${lastName} has been made inactive in the Highest Good Network as of ${endDate}. @@ -2040,6 +2047,19 @@ const userHelper = function () {

With Gratitude,

+

One Community

`; + recipients.push('onecommunityglobal@gmail.com'); + recipients = recipients.toString(); + emailSender(recipients, subject, emailBody, null, null, email); + } else if (isSet) { + const subject = `IMPORTANT: ${firstName} ${lastName} has been deactivated in the Highest Good Network`; + const emailBody = `

Management,

+ +

Please note that the final day for ${firstName} ${lastName} has been set in the Highest Good Network ${endDate}. + For a smooth transition, please confirm all your work is being wrapped up with this individual and nothing further will be needed on their part after this date.

+ +

With Gratitude,

+

One Community

`; recipients.push('onecommunityglobal@gmail.com'); recipients = recipients.toString(); @@ -2056,7 +2076,7 @@ const userHelper = function () { const recipients = emailReceivers.map((receiver) => receiver.email); const users = await userProfile.find( { isActive: true, endDate: { $exists: true } }, - '_id isActive endDate', + '_id isActive endDate isSet', ); for (let i = 0; i < users.length; i += 1) { const user = users[i]; @@ -2079,7 +2099,7 @@ const userHelper = function () { const id = user._id; const person = await userProfile.findById(id); const lastDay = moment(person.endDate).format('YYYY-MM-DD'); - logger.logInfo(`User with id: ${user._id} was de-acticated at ${moment().format()}.`); + logger.logInfo(`User with id: ${user._id} was de-activated at ${moment().format()}.`); person.teams.map(async (teamId) => { const managementEmails = await userHelper.getTeamManagementEmail(teamId); if (Array.isArray(managementEmails) && managementEmails.length > 0) { @@ -2094,6 +2114,7 @@ const userHelper = function () { lastDay, person.email, recipients, + person.isSet, ); } }