@@ -318,10 +318,11 @@ async function sendInterviewCompletedNotifications () {
318318 ]
319319 }
320320
321- const interviews = await Interview . findAll ( {
321+ let interviews = await Interview . findAll ( {
322322 where : filter ,
323323 raw : true
324324 } )
325+ interviews = _ . map ( _ . values ( _ . groupBy ( interviews , 'jobCandidateId' ) ) , ( interviews ) => _ . maxBy ( interviews , 'round' ) )
325326
326327 const jobCandidates = await JobCandidate . findAll ( { where : { id : _ . map ( interviews , 'jobCandidateId' ) } } )
327328 const jcMap = _ . keyBy ( jobCandidates , 'id' )
@@ -418,28 +419,27 @@ async function sendPostInterviewActionNotifications () {
418419 const projectJcs = _ . filter ( completedJobCandidates , jc => jc . jobId === projectJob . id )
419420 numCandidates += projectJcs . length
420421 for ( const projectJc of projectJcs ) {
421- for ( const interview of projectJc . interviews ) {
422- const d = await getDataForInterview ( interview , projectJc , projectJob )
423- if ( ! d ) { continue }
424- d . jobUrl = `${ config . TAAS_APP_URL } /${ projectId } /positions/${ projectJob . id } `
425- webNotifications . push ( {
426- serviceId : 'web' ,
427- type : template ,
428- details : {
429- recipients : projectTeamRecipients ,
430- contents : {
431- jobTitle : d . jobTitle ,
432- teamName : project . name ,
433- projectId,
434- jobId : projectJob . id ,
435- userHandle : d . handle
436- } ,
437- version : 1
438- }
439- } )
422+ const interview = _ . maxBy ( projectJc . interviews , 'round' )
423+ const d = await getDataForInterview ( interview , projectJc , projectJob )
424+ if ( ! d ) { continue }
425+ d . jobUrl = `${ config . TAAS_APP_URL } /${ projectId } /positions/${ projectJob . id } `
426+ webNotifications . push ( {
427+ serviceId : 'web' ,
428+ type : template ,
429+ details : {
430+ recipients : projectTeamRecipients ,
431+ contents : {
432+ jobTitle : d . jobTitle ,
433+ teamName : project . name ,
434+ projectId,
435+ jobId : projectJob . id ,
436+ userHandle : d . handle
437+ } ,
438+ version : 1
439+ }
440+ } )
440441
441- teamInterviews . push ( d )
442- }
442+ teamInterviews . push ( d )
443443 }
444444 }
445445
0 commit comments