Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : Email added for role change via bulkuser #556

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,10 @@ module.exports = {
captchaEnabledAPIs: ['/user/v1/account/login', '/user/v1/account/generateOtp', '/user/v1/account/registrationOtp'],
WRITE_ACCESS: 'w',
READ_ACCESS: 'r',
ROLE_DESCRIPTION: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sumanvpacewisdom add it in the notification template, besed on the role you can send the content, look for sendNotificationsToMentor for implementation.

MENTOR: 'As a Mentor: You will have the opportunity to guide and support mentees, sharing your knowledge and expertise to help them achieve their goals.',
MENTEE: 'As a Mentee: You will benefit from the guidance and support of a mentor, helping you to grow and develop in your personal and professional journey.',
SESSION_MANAGER:
'As a Session Manager: You will be responsible for organizing and managing mentoring sessions, ensuring that they run smoothly and effectively.',
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'

require('module-alias/register')
const moment = require('moment')

module.exports = {
up: async (queryInterface, Sequelize) => {
try {
const defaultOrgId = queryInterface.sequelize.options.defaultOrgId
// Your email template data
const emailTemplates = [
{
body: '<p>Dear {name},</p> <p>We wanted to inform you that your role on our platform has been updated.</p> <p>Your new role : {role}</p> <p>What this means for you:</p> <p>{description}</p>',
code: 'user_invites_role_change',
subject: 'Important: Role Updated on MentorEd',
},
]
// Check if email templates exist
const existingTemplates = await queryInterface.sequelize.query(
'SELECT code FROM notification_templates WHERE organization_id = :orgId',
{
replacements: { orgId: defaultOrgId },
type: Sequelize.QueryTypes.SELECT,
}
)

const newTemplates = emailTemplates.filter((template) => {
return !existingTemplates.some((existingTemplate) => existingTemplate.code === template.code)
})

// Insert new email templates
const notificationTemplateData = newTemplates.map((emailTemplate) => {
emailTemplate['status'] = 'ACTIVE'
emailTemplate['type'] = 'email'
emailTemplate['updated_at'] = moment().format()
emailTemplate['created_at'] = moment().format()
emailTemplate['organization_id'] = defaultOrgId
if (emailTemplate.code == 'email_footer') {
emailTemplate['type'] = 'emailFooter'
} else if (emailTemplate.code == 'email_header') {
emailTemplate['type'] = 'emailHeader'
} else {
emailTemplate['email_footer'] = 'email_footer'
emailTemplate['email_header'] = 'email_header'
}
return emailTemplate
})
if (notificationTemplateData.length != 0) {
await queryInterface.bulkInsert('notification_templates', notificationTemplateData, {})
}

const body = `<p>Dear {name},</p> Please find attached the status of your bulk upload activity.`
const updateData = { body }

const updateFilter = { code: 'invitee_upload_status', organization_id: defaultOrgId }
await queryInterface.bulkUpdate('notification_templates', updateData, updateFilter)
} catch (error) {
console.log('Error:', error)
}
},

down: async (queryInterface, Sequelize) => {
const defaultOrgId = queryInterface.sequelize.options.defaultOrgId

await queryInterface.bulkDelete('notification_templates', { organization_id: defaultOrgId }, {})
},
}
27 changes: 27 additions & 0 deletions src/services/userInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ module.exports = class UserInviteHelper {
user.organization_id
)

//fetch role change email template
const roleChangeEmailTemplate = await notificationTemplateQueries.findOneEmailTemplate(
process.env.ROLE_CHANGE_EMAIL_TEMPLATE_CODE,
user.organization_id
)

//find already invited users
const emailList = await userInviteQueries.findAll({ email: emailArray })
const existingInvitees = {}
Expand Down Expand Up @@ -387,10 +393,30 @@ module.exports = class UserInviteHelper {
})
}

let roleDescription

if (newRoles.includes('Mentor')) {
roleDescription = common.ROLE_DESCRIPTION.MENTOR
} else if (newRoles.includes('Mentee')) {
roleDescription = common.ROLE_DESCRIPTION.MENTEE
} else if (newRoles.includes('Session Manager')) {
roleDescription = common.ROLE_DESCRIPTION.SESSION_MANAGER
}

const updatedRoles = newRoles.length > 0 ? newRoles.join(',') : ''
const changeRoleRequestBody = {
email: invitee.email,
name: invitee.name,
role: updatedRoles,
description: roleDescription,
}
//remove user data from redis
const redisUserKey = common.redisUserPrefix + existingUser.id.toString()
await utils.redisDel(redisUserKey)
invitee.statusOrUserId = 'Success'
if (newRoles.length > 0 && roleChangeEmailTemplate) {
await this.sendInviteeEmail(roleChangeEmailTemplate, changeRoleRequestBody, null, {})
}
} else {
invitee.statusOrUserId = 'No updates needed. User details are already up to date'
}
Expand Down Expand Up @@ -547,6 +573,7 @@ module.exports = class UserInviteHelper {
appName: process.env.APP_NAME,
portalURL: process.env.PORTAL_URL,
roles: userData.roles || '',
description: userData.description || '',
}),
},
}
Expand Down