diff --git a/scripts/demo-email-notifications/index.js b/scripts/demo-email-notifications/index.js index e81a0aee..87ee16b8 100644 --- a/scripts/demo-email-notifications/index.js +++ b/scripts/demo-email-notifications/index.js @@ -41,10 +41,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 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 87ed60a6..90a6b58f 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')) const jobCandidates = await JobCandidate.findAll({ where: { id: _.map(interviews, 'jobCandidateId') } }) const jcMap = _.keyBy(jobCandidates, 'id') @@ -418,28 +419,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) } }