Skip to content

Commit

Permalink
Merge pull request #1084 from OneCommunityGlobal/Ivy-isSet-issues
Browse files Browse the repository at this point in the history
Ivy-set-final-day-emailTemplate
  • Loading branch information
one-community authored Aug 24, 2024
2 parents 51981df + b6d8cf4 commit e283940
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/controllers/userProfileController.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ const userProfileController = function (UserProfile, Project) {
endDate,
user.email,
recipients,
isSet,
);
auditIfProtectedAccountUpdated(
req.body.requestor.requestorId,
Expand Down
31 changes: 26 additions & 5 deletions src/helpers/userHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2030,16 +2030,36 @@ 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 = `<p>Management, </p>
<p>Please note that ${firstName} ${lastName} has been made inactive in the Highest Good Network as of ${endDate}.
Please confirm all your work with this individual has been wrapped up and nothing further is needed on their part. </p>
<p>With Gratitude, </p>
<p>One Community</p>`;
recipients.push('[email protected]');
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 = `<p>Management, </p>
<p>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. </p>
<p>With Gratitude, </p>
<p>One Community</p>`;
recipients.push('[email protected]');
recipients = recipients.toString();
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -2094,6 +2114,7 @@ const userHelper = function () {
lastDay,
person.email,
recipients,
person.isSet,
);
}
}
Expand Down

0 comments on commit e283940

Please sign in to comment.