Skip to content

Commit 5b39bc8

Browse files
committed
improve interview email notifications logic
- support re-scheduled interviews for upcoming notifications - support scheduled and re-scheduled interviews for action reminders - support re-scheduled and completed interviews for complete interview reminders - use start date as a starting point for complete interview reminders
1 parent 6b5a972 commit 5b39bc8

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

scripts/demo-email-notifications/index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,28 @@ async function resetNotificationRecords () {
4444
// reset completed interview records
4545
localLogger.info('reset completed interview records')
4646
const pastTime = moment.duration(config.INTERVIEW_COMPLETED_PAST_TIME)
47-
const endTimestamp = moment().subtract(pastTime).add(config.INTERVIEW_COMPLETED_MATCH_WINDOW).toDate()
47+
const completedStartTimestamp = moment().subtract(pastTime).add(config.INTERVIEW_COMPLETED_MATCH_WINDOW).toDate()
4848
const completedInterview = await Interview.findById('9efd72c3-1dc7-4ce2-9869-8cca81d0adeb')
4949
const duration = 30
50-
const completedStartTimestamp = moment().subtract(pastTime).subtract(30, 'm').toDate()
51-
await completedInterview.update({ startTimestamp: completedStartTimestamp, duration, endTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
50+
const completedEndTimestamp = moment(completedStartTimestamp).clone().add(30, 'm').toDate()
51+
await completedInterview.update({ startTimestamp: completedStartTimestamp, duration, endTimeStamp: completedEndTimestamp, status: Interviews.Status.Scheduled, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
5252

5353
// reset post interview candidate action reminder records
5454
localLogger.info('reset post interview candidate action reminder records')
5555
const jobCandidate = await JobCandidate.findById('881a19de-2b0c-4bb9-b36a-4cb5e223bdb5')
5656
await jobCandidate.update({ status: 'interview' })
5757
const c2Interview = await Interview.findById('077aa2ca-5b60-4ad9-a965-1b37e08a5046')
58-
await c2Interview.update({ startTimestamp: moment().subtract(moment.duration(config.POST_INTERVIEW_ACTION_MATCH_WINDOW)).subtract(30, 'm').toDate(), duration, endTimestamp, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
58+
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' })
5959
const jobCandidateWithinOneDay = await JobCandidate.findById('827ee401-df04-42e1-abbe-7b97ce7937ff')
6060
await jobCandidateWithinOneDay.update({ status: 'interview' })
6161
const interviewWithinOneDay = await Interview.findById('3144fa65-ea1a-4bec-81b0-7cb1c8845826')
62-
await interviewWithinOneDay.update({ startTimestamp: completedStartTimestamp, duration, endTimestamp, guestNames: ['guest1', 'guest2'], hostName: 'hostName' })
62+
await interviewWithinOneDay.update({
63+
startTimestamp: moment(completedStartTimestamp).clone().add(config.INTERVIEW_COMPLETED_MATCH_WINDOW), // add WINDOW to not receive "completed interview" email
64+
duration,
65+
endTimeStamp: moment(completedEndTimestamp).clone().add(config.INTERVIEW_COMPLETED_MATCH_WINDOW), // add WINDOW to not receive "completed interview" email
66+
guestNames: ['guest1', 'guest2'],
67+
hostName: 'hostName'
68+
})
6369

6470
// reset upcoming resource booking expiration records
6571
localLogger.info('reset upcoming resource booking expiration records')

src/services/NotificationsSchedulerService.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,12 @@ async function sendInterviewComingUpNotifications () {
214214
const filter = {
215215
[Op.and]: [
216216
{
217-
status: { [Op.eq]: constants.Interviews.Status.Scheduled }
217+
status: {
218+
[Op.in]: [
219+
constants.Interviews.Status.Scheduled,
220+
constants.Interviews.Status.Rescheduled
221+
]
222+
}
218223
},
219224
{
220225
startTimestamp: timestampFilter
@@ -276,10 +281,16 @@ async function sendInterviewCompletedNotifications () {
276281
const filter = {
277282
[Op.and]: [
278283
{
279-
status: { [Op.eq]: constants.Interviews.Status.Scheduled }
284+
status: {
285+
[Op.in]: [
286+
constants.Interviews.Status.Scheduled,
287+
constants.Interviews.Status.Rescheduled,
288+
constants.Interviews.Status.Completed
289+
]
290+
}
280291
},
281292
{
282-
endTimestamp: {
293+
startTimestamp: {
283294
[Op.and]: [
284295
{
285296
[Op.gte]: rangeStart
@@ -337,7 +348,13 @@ async function sendPostInterviewActionNotifications () {
337348
as: 'interviews',
338349
required: true,
339350
where: {
340-
status: constants.Interviews.Status.Completed,
351+
status: {
352+
[Op.in]: [
353+
constants.Interviews.Status.Scheduled,
354+
constants.Interviews.Status.Rescheduled,
355+
constants.Interviews.Status.Completed
356+
]
357+
},
341358
startTimestamp: {
342359
[Op.lte]: moment.utc().subtract(moment.duration(config.POST_INTERVIEW_ACTION_MATCH_WINDOW))
343360
}

0 commit comments

Comments
 (0)