Skip to content

Commit 04181db

Browse files
authored
Merge pull request #650 from yoution/issue-615
fix: issue #615
2 parents d9663df + 1eef453 commit 04181db

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

scripts/demo-email-notifications/README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ This script does 2 things:
2626
TAAS_NOTIFICATION_RESOURCE_BOOKING_EXPIRATION_SENDGRID_TEMPLATE_ID=7
2727
TAAS_NOTIFICATION_TEAM_CREATED_SENDGRID_TEMPLATE_ID=8
2828
TAAS_NOTIFICATION_JOB_CREATED_SENDGRID_TEMPLATE_ID=9
29-
TAAS_NOTIFICATION_RESOURCE_BOOKING_PLACED_SENDGRID_TEMPLATE_ID=10
30-
TAAS_NOTIFICATION_INTERVIEWS_OVERLAPPING_SENDGRID_TEMPLATE_ID=11
31-
TAAS_NOTIFICATION_JOB_CANDIDATE_SELECTED_SENDGRID_TEMPLATE_ID=12
29+
TAAS_NOTIFICATION_INTERVIEWS_OVERLAPPING_SENDGRID_TEMPLATE_ID=10
30+
TAAS_NOTIFICATION_JOB_CANDIDATE_SELECTED_SENDGRID_TEMPLATE_ID=11
31+
TAAS_NOTIFICATION_RESOURCE_BOOKING_PLACED_SENDGRID_TEMPLATE_ID=12
3232
TAAS_NOTIFICATION_INTERVIEW_SCHEDULE_REMINDER_SENDGRID_TEMPLATE_ID=13
3333
TAAS_NOTIFICATION_INTERVIEW_EXPIRED_GUEST_SENDGRID_TEMPLATE_ID=14
3434
TAAS_NOTIFICATION_INTERVIEW_EXPIRED_HOST_SENDGRID_TEMPLATE_ID=15
3535
TAAS_NOTIFICATION_INTERVIEW_INVITATION_SENDGRID_TEMPLATE_ID=16
3636
TAAS_NOTIFICATION_INTERVIEW_LINK_FOR_HOST_SENDGRID_TEMPLATE_ID=17
3737
TAAS_NOTIFICATION_INTERVIEW_LINK_FOR_GUEST_SENDGRID_TEMPLATE_ID=18
38+
TAAS_NOTIFICATION_INTERVIEW_RESCHEDULED_HOST_SENDGRID_TEMPLATE_ID=19
39+
TAAS_NOTIFICATION_INTERVIEW_RESCHEDULED_GUEST_SENDGRID_TEMPLATE_ID=20
40+
TAAS_NOTIFICATION_INTERVIEW_CANCELLED_HOST_SENDGRID_TEMPLATE_ID=21
41+
TAAS_NOTIFICATION_INTERVIEW_CANCELLED_GUEST_SENDGRID_TEMPLATE_ID=22
3842
```
3943
2. Config `SLACK_WEBHOOK_URL` env, if you want to send slack notifications
4044

scripts/demo-email-notifications/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function resetNotificationRecords () {
4949
localLogger.info('reset coming up interview records')
5050
const interview = await Interview.findById('976d23a9-5710-453f-99d9-f57a588bb610')
5151
const startTimestamp = moment().add(moment.duration(config.INTERVIEW_COMING_UP_REMIND_TIME[0])).add(config.INTERVIEW_COMING_UP_MATCH_WINDOW).toDate()
52-
await interview.update({ startTimestamp, duration: 30, status: Interviews.Status.Scheduled, guestNames: ['test1', 'test2'], hostName: 'hostName' })
52+
await interview.update({ startTimestamp, duration: 30, status: Interviews.Status.Scheduled, guestNames: ['test1', 'test2'], hostName: 'hostName', guestTimezone: 'Europe/London' })
5353

5454
// reset completed interview records
5555
localLogger.info('reset completed interview records')
@@ -61,6 +61,8 @@ async function resetNotificationRecords () {
6161
await completedInterview.update({ startTimestamp: completedStartTimestamp, duration, endTimeStamp: completedEndTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
6262
const completedInterview2 = await Interview.findById('3144fa65-ea1a-4bec-81b0-7cb1c8845826')
6363
await completedInterview2.update({ startTimestamp: completedStartTimestamp, duration, endTimeStamp: completedEndTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
64+
const jobCandidateForInterview = await JobCandidate.findById('a4ea7bcf-5b99-4381-b99c-a9bd05d83a36')
65+
await jobCandidateForInterview.update({ status: 'interview' })
6466

6567
// reset post interview candidate action reminder records
6668
localLogger.info('reset post interview candidate action reminder records')

src/services/NotificationsSchedulerService.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ async function getProjectWithId (projectId) {
4444

4545
/**
4646
* extract the members of projects and build recipients list out of them
47-
* we can use `userId` to identify recipients
47+
* we can use `email` to identify recipients
4848
* @param project the project
4949
* @returns {string[]} array of recipients
5050
*/
5151
function buildProjectTeamRecipients (project) {
52-
const recipients = _.unionBy(_.map(project.members, m => _.pick(m, 'userId')), 'userId')
52+
const recipients = _.unionBy(_.map(project.members, m => _.pick(m, 'email')), 'email')
5353
if (_.isEmpty(recipients)) {
5454
localLogger.error(`No recipients for projectId:${project.id}`, 'buildProjectTeamRecipients')
5555
}
@@ -276,11 +276,11 @@ async function sendInterviewComingUpNotifications () {
276276
const data = await getDataForInterview(interview)
277277
if (!data) { continue }
278278

279-
if (!_.isEmpty(interview.hostEmail)) {
279+
if (!_.isEmpty(data.hostEmail)) {
280280
data.startTime = formatInterviewTime(interview, { forInterviewHost: true })
281281
sendNotification({}, {
282282
template: 'taas.notification.interview-coming-up-host',
283-
recipients: [{ email: interview.hostEmail }],
283+
recipients: [{ email: data.hostEmail }],
284284
data
285285
})
286286

@@ -289,12 +289,12 @@ async function sendInterviewComingUpNotifications () {
289289
localLogger.error(`Interview id: ${interview.id} host email not present`, 'sendInterviewComingUpNotifications')
290290
}
291291

292-
if (!_.isEmpty(interview.guestEmails)) {
292+
if (!_.isEmpty(data.guestEmail)) {
293293
data.startTime = formatInterviewTime(interview, { forInterviewGuest: true })
294294
// send guest emails
295295
sendNotification({}, {
296296
template: 'taas.notification.interview-coming-up-guest',
297-
recipients: interview.guestEmails.map((email) => ({ email })),
297+
recipients: [{ email: data.guestEmail }],
298298
data
299299
})
300300

@@ -354,22 +354,23 @@ async function sendInterviewCompletedNotifications () {
354354

355355
let sentCount = 0
356356
for (const interview of interviews) {
357-
if (_.isEmpty(interview.hostEmail)) {
358-
localLogger.error(`Interview id: ${interview.id} host email not present`)
359-
continue
360-
}
361357
if (!jcMap[interview.jobCandidateId] || jcMap[interview.jobCandidateId].status !== constants.JobCandidateStatus.INTERVIEW) {
362358
localLogger.error(`Interview id: ${interview.id} job candidate status is not ${constants.JobCandidateStatus.INTERVIEW}`)
363359
continue
364360
}
365361

366362
const data = await getDataForInterview(interview, jcMap[interview.jobCandidateId])
363+
364+
if (_.isEmpty(data.hostEmail)) {
365+
localLogger.error(`Interview id: ${interview.id} host email not present`)
366+
continue
367+
}
367368
if (!data) { continue }
368369
data.startTime = formatInterviewTime(interview, { forInterviewHost: true })
369370

370371
sendNotification({}, {
371372
template: 'taas.notification.interview-awaits-resolution',
372-
recipients: [{ email: interview.hostEmail }],
373+
recipients: [{ email: data.hostEmail }],
373374
data
374375
})
375376

0 commit comments

Comments
 (0)