@@ -40,18 +40,18 @@ async function getProjectWithId (projectId) {
40
40
}
41
41
42
42
/**
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
44
45
* @param project the project
45
- * @returns {string[] } array of emails
46
+ * @returns {string[] } array of recipients
46
47
*/
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' )
52
52
}
53
53
54
- return recipientEmails
54
+ return recipients
55
55
}
56
56
57
57
/**
@@ -131,7 +131,7 @@ async function sendCandidatesAvailableNotifications () {
131
131
const project = await getProjectWithId ( projectId )
132
132
if ( ! project ) { continue }
133
133
134
- const recipientEmails = getProjectMembersEmails ( project )
134
+ const projectTeamRecipients = buildProjectTeamRecipients ( project )
135
135
const projectJobs = _ . filter ( jobs , job => job . projectId === projectId )
136
136
137
137
const teamJobs = [ ]
@@ -170,7 +170,7 @@ async function sendCandidatesAvailableNotifications () {
170
170
171
171
sendNotification ( { } , {
172
172
template : 'taas.notification.candidates-available-for-review' ,
173
- recipients : recipientEmails ,
173
+ recipients : projectTeamRecipients ,
174
174
data : {
175
175
teamName : project . name ,
176
176
teamJobs,
@@ -379,7 +379,7 @@ async function sendPostInterviewActionNotifications () {
379
379
const project = await getProjectWithId ( projectId )
380
380
if ( ! project ) { continue }
381
381
const webNotifications = [ ]
382
- const recipientEmails = getProjectMembersEmails ( project )
382
+ const projectTeamRecipients = buildProjectTeamRecipients ( project )
383
383
const projectJobs = _ . filter ( jobs , job => job . projectId === projectId )
384
384
const teamInterviews = [ ]
385
385
let numCandidates = 0
@@ -395,7 +395,7 @@ async function sendPostInterviewActionNotifications () {
395
395
serviceId : 'web' ,
396
396
type : template ,
397
397
details : {
398
- recipients : _ . map ( _ . uniq ( recipientEmails ) , function ( re ) { return { email : re } } ) ,
398
+ recipients : projectTeamRecipients ,
399
399
contents : {
400
400
jobTitle : d . jobTitle ,
401
401
teamName : project . name ,
@@ -414,7 +414,7 @@ async function sendPostInterviewActionNotifications () {
414
414
415
415
sendNotification ( { } , {
416
416
template,
417
- recipients : recipientEmails ,
417
+ recipients : projectTeamRecipients ,
418
418
data : {
419
419
teamName : project . name ,
420
420
numCandidates,
@@ -472,7 +472,7 @@ async function sendResourceBookingExpirationNotifications () {
472
472
for ( const projectId of projectIds ) {
473
473
const project = await getProjectWithId ( projectId )
474
474
if ( ! project ) { continue }
475
- const recipientEmails = getProjectMembersEmails ( project )
475
+ const projectTeamRecipients = buildProjectTeamRecipients ( project )
476
476
const projectJobs = _ . filter ( jobs , job => job . projectId === projectId )
477
477
478
478
let numResourceBookings = 0
@@ -501,7 +501,7 @@ async function sendResourceBookingExpirationNotifications () {
501
501
serviceId : 'web' ,
502
502
type : template ,
503
503
details : {
504
- recipients : _ . map ( _ . uniq ( recipientEmails ) , function ( re ) { return { email : re } } ) ,
504
+ recipients : projectTeamRecipients ,
505
505
contents : {
506
506
teamName : project . name ,
507
507
projectId,
@@ -515,7 +515,7 @@ async function sendResourceBookingExpirationNotifications () {
515
515
516
516
sendNotification ( { } , {
517
517
template,
518
- recipients : recipientEmails ,
518
+ recipients : projectTeamRecipients ,
519
519
data : {
520
520
teamName : project . name ,
521
521
numResourceBookings,
0 commit comments