From 81b557308f91bc15572fa9c44dd9daaf27180c96 Mon Sep 17 00:00:00 2001 From: xxcxy Date: Thu, 9 Sep 2021 09:51:19 +0800 Subject: [PATCH 1/3] Interview completed email notification should not be sent if action was taken on the Job Candidate --- scripts/demo-email-notifications/index.js | 2 ++ src/services/NotificationsSchedulerService.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/scripts/demo-email-notifications/index.js b/scripts/demo-email-notifications/index.js index 328b3fa8..217e7baf 100644 --- a/scripts/demo-email-notifications/index.js +++ b/scripts/demo-email-notifications/index.js @@ -36,6 +36,8 @@ async function resetNotificationRecords () { const duration = 30 const completedEndTimestamp = moment(completedStartTimestamp).clone().add(30, 'm').toDate() await completedInterview.update({ startTimestamp: completedStartTimestamp, duration, endTimeStamp: completedEndTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' }) + const completedInterview2 = await Interview.findById('3144fa65-ea1a-4bec-81b0-7cb1c8845826') + await completedInterview2.update({ startTimestamp: completedStartTimestamp, duration, endTimeStamp: completedEndTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' }) // reset post interview candidate action reminder records localLogger.info('reset post interview candidate action reminder records') diff --git a/src/services/NotificationsSchedulerService.js b/src/services/NotificationsSchedulerService.js index 3bd24704..d83a3b09 100644 --- a/src/services/NotificationsSchedulerService.js +++ b/src/services/NotificationsSchedulerService.js @@ -323,6 +323,9 @@ async function sendInterviewCompletedNotifications () { raw: true }) + const jobCandidates = await JobCandidate.findAll({ where: { id: _.map(interviews, 'jobCandidateId') } }) + const jcMap = _.keyBy(jobCandidates, 'id') + localLogger.debug(`[sendInterviewCompletedNotifications]: Found ${interviews.length} interviews which must be ended by now.`) let sentCount = 0 @@ -331,6 +334,10 @@ async function sendInterviewCompletedNotifications () { localLogger.error(`Interview id: ${interview.id} host email not present`) continue } + if (!jcMap[interview.jobCandidateId] || jcMap[interview.jobCandidateId].status !== constants.JobCandidateStatus.INTERVIEW) { + localLogger.error(`Interview id: ${interview.id} job candidate status is not ${constants.JobCandidateStatus.INTERVIEW}`) + continue + } const data = await getDataForInterview(interview) if (!data) { continue } From 339068d4bcda3a7d6da9652c204c0069cfd858f5 Mon Sep 17 00:00:00 2001 From: xxcxy Date: Thu, 9 Sep 2021 10:11:09 +0800 Subject: [PATCH 2/3] do not find jc twice --- src/services/NotificationsSchedulerService.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/NotificationsSchedulerService.js b/src/services/NotificationsSchedulerService.js index d83a3b09..87ed60a6 100644 --- a/src/services/NotificationsSchedulerService.js +++ b/src/services/NotificationsSchedulerService.js @@ -339,7 +339,7 @@ async function sendInterviewCompletedNotifications () { continue } - const data = await getDataForInterview(interview) + const data = await getDataForInterview(interview, jcMap[interview.jobCandidateId]) if (!data) { continue } sendNotification({}, { From cf8f6fe558135cc17461c5e7a9b6a85c335faf0c Mon Sep 17 00:00:00 2001 From: xxcxy Date: Thu, 9 Sep 2021 21:02:26 +0800 Subject: [PATCH 3/3] fix notification demo data --- scripts/demo-email-notifications/index.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/scripts/demo-email-notifications/index.js b/scripts/demo-email-notifications/index.js index 217e7baf..e81a0aee 100644 --- a/scripts/demo-email-notifications/index.js +++ b/scripts/demo-email-notifications/index.js @@ -45,16 +45,6 @@ async function resetNotificationRecords () { await jobCandidate.update({ status: 'interview' }) const c2Interview = await Interview.findById('077aa2ca-5b60-4ad9-a965-1b37e08a5046') await c2Interview.update({ startTimestamp: moment().subtract(moment.duration(config.POST_INTERVIEW_ACTION_MATCH_WINDOW)).subtract(30, 'm').toDate(), duration, endTimeStamp: completedEndTimestamp, guestNames: ['guest1', 'guest2'], hostName: 'hostName' }) - const jobCandidateWithinOneDay = await JobCandidate.findById('827ee401-df04-42e1-abbe-7b97ce7937ff') - await jobCandidateWithinOneDay.update({ status: 'interview' }) - const interviewWithinOneDay = await Interview.findById('3144fa65-ea1a-4bec-81b0-7cb1c8845826') - await interviewWithinOneDay.update({ - startTimestamp: moment(completedStartTimestamp).clone().add(config.INTERVIEW_COMPLETED_MATCH_WINDOW), // add WINDOW to not receive "completed interview" email - duration, - endTimeStamp: moment(completedEndTimestamp).clone().add(config.INTERVIEW_COMPLETED_MATCH_WINDOW), // add WINDOW to not receive "completed interview" email - guestNames: ['guest1', 'guest2'], - hostName: 'hostName' - }) // reset upcoming resource booking expiration records localLogger.info('reset upcoming resource booking expiration records')