@@ -4,10 +4,17 @@ import { pairingSessionsRepo } from '@repos/pairingSessionsRepo';
44import { userRepo } from '@repos/userRepo' ;
55import { chatService } from '@/services/ChatService' ;
66import { App } from '@slack/bolt' ;
7+ import { WebClient } from '@/slackTypes' ;
78import { formatSlot , mention , ul } from '@utils/text' ;
89import { reviewLockManager } from '@utils/reviewLockManager' ;
910import log from '@utils/log' ;
1011
12+ async function finalize ( client : WebClient , threadId : string , message : string ) : Promise < void > {
13+ await chatService . replyToReviewThread ( client , threadId , message ) ;
14+ await pairingSessionsRepo . remove ( threadId ) ;
15+ reviewLockManager . releaseLock ( threadId ) ;
16+ }
17+
1118export function findConfirmedSlots ( interview : PairingSession ) : PairingSlot [ ] {
1219 return interview . slots . filter ( slot =>
1320 isSlotConfirmed ( slot , interview . format , interview . teammatesNeededCount ) ,
@@ -51,29 +58,36 @@ export const pairingSessionCloser = {
5158 ) . values ( ) ,
5259 ) ;
5360 const slotLines = confirmedSlots . map ( s => formatSlot ( s . date , s . startTime , s . endTime ) ) ;
54- await chatService . replyToReviewThread (
55- app . client ,
56- threadId ,
61+ const message =
5762 `${ mention ( { id : interview . requestorId } ) } Pairing session for *${ interview . candidateName } * is ready to schedule!\n\n` +
58- `*Teammates:* ${ teammates . map ( t => mention ( { id : t . userId } ) ) . join ( ', ' ) } \n\n` +
59- `*Available slots (${ confirmedSlots . length } ):*\n${ ul ( ...slotLines ) } ` ,
60- ) ;
63+ `*Teammates:* ${ teammates . map ( t => mention ( { id : t . userId } ) ) . join ( ', ' ) } \n\n` +
64+ `*Available slots (${ confirmedSlots . length } ):*\n${ ul ( ...slotLines ) } ` ;
6165 await Promise . all ( teammates . map ( t => userRepo . markNowAsLastPairingReviewedDate ( t . userId ) ) ) ;
62- await pairingSessionsRepo . remove ( threadId ) ;
63- reviewLockManager . releaseLock ( threadId ) ;
66+ await finalize ( app . client , threadId , message ) ;
6467 return true ;
6568 }
6669
6770 const isUnfulfilled = interview . pendingTeammates . length === 0 ;
6871
6972 if ( isUnfulfilled ) {
70- await chatService . replyToReviewThread (
71- app . client ,
72- threadId ,
73- `${ mention ( { id : interview . requestorId } ) } No teammates available to cover all slots for ${ interview . candidateName } 's pairing session.` ,
74- ) ;
75- await pairingSessionsRepo . remove ( threadId ) ;
76- reviewLockManager . releaseLock ( threadId ) ;
73+ const slotsWithInterest = interview . slots . filter ( s => s . interestedTeammates . length > 0 ) ;
74+ const header = `${ mention ( { id : interview . requestorId } ) } Couldn't fill all slots for *${ interview . candidateName } *'s pairing session.` ;
75+
76+ const message =
77+ slotsWithInterest . length > 0
78+ ? `${ header } \n\n` +
79+ `Some teammates did sign up — you may be able to reach out to them directly:\n` +
80+ ul (
81+ ...slotsWithInterest . map (
82+ s =>
83+ `${ formatSlot ( s . date , s . startTime , s . endTime ) } — ${ s . interestedTeammates
84+ . map ( t => mention ( { id : t . userId } ) )
85+ . join ( ', ' ) } `,
86+ ) ,
87+ )
88+ : `${ header } No teammates signed up.` ;
89+
90+ await finalize ( app . client , threadId , message ) ;
7791 return true ;
7892 }
7993
0 commit comments