Skip to content

Commit f36704f

Browse files
committed
fix all team notifications recipietns
use "userId" that are always provided unlike "email" which is we have to retrieve separately for project members
1 parent 719487c commit f36704f

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

src/eventHandlers/JobEventHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async function sendNotifications (payload) {
104104
type: 'taas.notification.job-created',
105105
details: {
106106
from: template.from,
107-
recipients: _.map(project.members, m => _.pick(m, 'email')),
107+
recipients: _.map(project.members, m => _.pick(m, 'userId')),
108108
data,
109109
sendgridTemplateId: template.sendgridTemplateId,
110110
version: 'v3'

src/eventHandlers/ResourceBookingEventHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function sendPlacedNotifications (payload) {
8686
const project = await helper.getProjectById({ isMachine: true }, resourceBooking.projectId)
8787
const user = await helper.getUserById(resourceBooking.userId)
8888
const job = await models.Job.findById(resourceBooking.jobId)
89-
const recipients = _.map(project.members, m => _.pick(m, 'email'))
89+
const recipients = _.map(project.members, m => _.pick(m, 'userId'))
9090
const jobUrl = `${config.TAAS_APP_URL}/${project.id}/positions/${job.id}`
9191
const teamUrl = `${config.TAAS_APP_URL}/${project.id}`
9292
const data = {

src/eventHandlers/TeamEventHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async function sendNotificationEmail (payload) {
3737
type: 'taas.notification.team-created',
3838
details: {
3939
from: template.from,
40-
recipients: _.map(payload.project.members, m => _.pick(m, 'email')),
40+
recipients: _.map(payload.project.members, m => _.pick(m, 'userId')),
4141
data,
4242
sendgridTemplateId: template.sendgridTemplateId,
4343
version: 'v3'

src/services/NotificationsSchedulerService.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ async function getProjectWithId (projectId) {
4040
}
4141

4242
/**
43-
* extract the members emails from the given project
43+
* extract the members of projects and build recipients list out of them
44+
* we can use `userId` to identify recipients
4445
* @param project the project
45-
* @returns {string[]} array of emails
46+
* @returns {string[]} array of recipients
4647
*/
47-
function getProjectMembersEmails (project) {
48-
let recipientEmails = _.map(_.get(project, 'members', []), member => member.email)
49-
recipientEmails = _.filter(recipientEmails, email => email)
50-
if (_.isEmpty(recipientEmails)) {
51-
localLogger.error(`No recipients for projectId:${project.id}`, 'getProjectMembersEmails')
48+
function buildProjectTeamRecipients (project) {
49+
const recipients = _.unionBy(_.map(project.members, m => _.pick(m, 'userId')), 'userId')
50+
if (_.isEmpty(recipients)) {
51+
localLogger.error(`No recipients for projectId:${project.id}`, 'buildProjectTeamRecipients')
5252
}
5353

54-
return recipientEmails
54+
return recipients
5555
}
5656

5757
/**
@@ -131,7 +131,7 @@ async function sendCandidatesAvailableNotifications () {
131131
const project = await getProjectWithId(projectId)
132132
if (!project) { continue }
133133

134-
const recipientEmails = getProjectMembersEmails(project)
134+
const projectTeamRecipients = buildProjectTeamRecipients(project)
135135
const projectJobs = _.filter(jobs, job => job.projectId === projectId)
136136

137137
const teamJobs = []
@@ -170,7 +170,7 @@ async function sendCandidatesAvailableNotifications () {
170170

171171
sendNotification({}, {
172172
template: 'taas.notification.candidates-available-for-review',
173-
recipients: recipientEmails,
173+
recipients: projectTeamRecipients,
174174
data: {
175175
teamName: project.name,
176176
teamJobs,
@@ -379,7 +379,7 @@ async function sendPostInterviewActionNotifications () {
379379
const project = await getProjectWithId(projectId)
380380
if (!project) { continue }
381381
const webNotifications = []
382-
const recipientEmails = getProjectMembersEmails(project)
382+
const projectTeamRecipients = buildProjectTeamRecipients(project)
383383
const projectJobs = _.filter(jobs, job => job.projectId === projectId)
384384
const teamInterviews = []
385385
let numCandidates = 0
@@ -395,7 +395,7 @@ async function sendPostInterviewActionNotifications () {
395395
serviceId: 'web',
396396
type: template,
397397
details: {
398-
recipients: _.map(_.uniq(recipientEmails), function (re) { return { email: re } }),
398+
recipients: projectTeamRecipients,
399399
contents: {
400400
jobTitle: d.jobTitle,
401401
teamName: project.name,
@@ -414,7 +414,7 @@ async function sendPostInterviewActionNotifications () {
414414

415415
sendNotification({}, {
416416
template,
417-
recipients: recipientEmails,
417+
recipients: projectTeamRecipients,
418418
data: {
419419
teamName: project.name,
420420
numCandidates,
@@ -472,7 +472,7 @@ async function sendResourceBookingExpirationNotifications () {
472472
for (const projectId of projectIds) {
473473
const project = await getProjectWithId(projectId)
474474
if (!project) { continue }
475-
const recipientEmails = getProjectMembersEmails(project)
475+
const projectTeamRecipients = buildProjectTeamRecipients(project)
476476
const projectJobs = _.filter(jobs, job => job.projectId === projectId)
477477

478478
let numResourceBookings = 0
@@ -501,7 +501,7 @@ async function sendResourceBookingExpirationNotifications () {
501501
serviceId: 'web',
502502
type: template,
503503
details: {
504-
recipients: _.map(_.uniq(recipientEmails), function (re) { return { email: re } }),
504+
recipients: projectTeamRecipients,
505505
contents: {
506506
teamName: project.name,
507507
projectId,
@@ -515,7 +515,7 @@ async function sendResourceBookingExpirationNotifications () {
515515

516516
sendNotification({}, {
517517
template,
518-
recipients: recipientEmails,
518+
recipients: projectTeamRecipients,
519519
data: {
520520
teamName: project.name,
521521
numResourceBookings,

0 commit comments

Comments
 (0)