From ae960999905f2c4eda385f703d2e4cd6136526ca Mon Sep 17 00:00:00 2001 From: xxcxy Date: Thu, 9 Sep 2021 12:49:24 +0800 Subject: [PATCH] fix Issues with Post Interview Action Reminder email notification when interview 2 is scheduled --- scripts/demo-email-notifications/index.js | 16 ++----- src/services/NotificationsSchedulerService.js | 44 +++++++++---------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/scripts/demo-email-notifications/index.js b/scripts/demo-email-notifications/index.js index 328b3fa8..2a23dedb 100644 --- a/scripts/demo-email-notifications/index.js +++ b/scripts/demo-email-notifications/index.js @@ -39,20 +39,12 @@ async function resetNotificationRecords () { // reset post interview candidate action reminder records localLogger.info('reset post interview candidate action reminder records') - const jobCandidate = await JobCandidate.findById('881a19de-2b0c-4bb9-b36a-4cb5e223bdb5') + const jobCandidate = await JobCandidate.findById('827ee401-df04-42e1-abbe-7b97ce7937ff') await jobCandidate.update({ status: 'interview' }) - const c2Interview = await Interview.findById('077aa2ca-5b60-4ad9-a965-1b37e08a5046') + const c2Interview = await Interview.findById('3144fa65-ea1a-4bec-81b0-7cb1c8845826') 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' - }) + const c2InterviewR2 = await Interview.findById('b1f7ba76-640f-47e2-9463-59e51b51ec60') + await c2InterviewR2.update({ status: 'Scheduled', startTimestamp: moment().subtract(moment.duration(config.POST_INTERVIEW_ACTION_MATCH_WINDOW)).subtract(30, 'm').toDate(), duration, endTimeStamp: completedEndTimestamp, guestNames: ['guest1', 'guest2'], hostName: 'hostName' }) // reset upcoming resource booking expiration records localLogger.info('reset upcoming resource booking expiration records') diff --git a/src/services/NotificationsSchedulerService.js b/src/services/NotificationsSchedulerService.js index 3bd24704..6bc57adc 100644 --- a/src/services/NotificationsSchedulerService.js +++ b/src/services/NotificationsSchedulerService.js @@ -318,10 +318,11 @@ async function sendInterviewCompletedNotifications () { ] } - const interviews = await Interview.findAll({ + let interviews = await Interview.findAll({ where: filter, raw: true }) + interviews = _.map(_.values(_.groupBy(interviews, 'jobCandidateId')), (interviews) => _.maxBy(interviews, 'round')) localLogger.debug(`[sendInterviewCompletedNotifications]: Found ${interviews.length} interviews which must be ended by now.`) @@ -411,28 +412,27 @@ async function sendPostInterviewActionNotifications () { const projectJcs = _.filter(completedJobCandidates, jc => jc.jobId === projectJob.id) numCandidates += projectJcs.length for (const projectJc of projectJcs) { - for (const interview of projectJc.interviews) { - const d = await getDataForInterview(interview, projectJc, projectJob) - if (!d) { continue } - d.jobUrl = `${config.TAAS_APP_URL}/${projectId}/positions/${projectJob.id}` - webNotifications.push({ - serviceId: 'web', - type: template, - details: { - recipients: projectTeamRecipients, - contents: { - jobTitle: d.jobTitle, - teamName: project.name, - projectId, - jobId: projectJob.id, - userHandle: d.handle - }, - version: 1 - } - }) + const interview = _.maxBy(projectJc.interviews, 'round') + const d = await getDataForInterview(interview, projectJc, projectJob) + if (!d) { continue } + d.jobUrl = `${config.TAAS_APP_URL}/${projectId}/positions/${projectJob.id}` + webNotifications.push({ + serviceId: 'web', + type: template, + details: { + recipients: projectTeamRecipients, + contents: { + jobTitle: d.jobTitle, + teamName: project.name, + projectId, + jobId: projectJob.id, + userHandle: d.handle + }, + version: 1 + } + }) - teamInterviews.push(d) - } + teamInterviews.push(d) } }