1- import { ChangeRequest , daysBetween , Task , UserPreview , wbsPipe , WorkPackage } from 'shared' ;
1+ import { ChangeRequest , daysBetween , Task , UserPreview , wbsPipe , calculateEndDate } from 'shared' ;
22import { User } from '@prisma/client' ;
33import { editMessage , reactToMessage , replyToMessageInThread , sendMessage } from '../integrations/slack' ;
44import { getUserFullName , getUserSlackId } from './users.utils' ;
@@ -8,9 +8,12 @@ import { Change_Request, Design_Review, Team, WBS_Element } from '@prisma/client
88import { UserWithSettings } from './auth.utils' ;
99import { usersToSlackPings , userToSlackPing } from './notifications.utils' ;
1010import { addHours , meetingStartTimePipe } from './design-reviews.utils' ;
11+ import { WorkPackageQueryArgs } from '../prisma-query-args/work-packages.query-args' ;
12+ import { Prisma } from '@prisma/client' ;
13+ import { userTransformer } from '../transformers/user.transformer' ;
1114
1215// build the "due" string for the upcoming deadlines slack message
13- const buildDueString = ( daysUntilDeadline : number ) : string => {
16+ export const buildDueString = ( daysUntilDeadline : number ) : string => {
1417 if ( daysUntilDeadline < 0 ) return `was due *${ daysUntilDeadline * - 1 } days ago!*` ;
1518 else if ( daysUntilDeadline === 0 ) return `is due today!` ;
1619 return `is due in ${ daysUntilDeadline } days!` ;
@@ -24,25 +27,27 @@ const buildUserString = (lead?: UserPreview, slackId?: string): string => {
2427 return '(no project lead)' ;
2528} ;
2629
27- export const sendSlackUpcomingDeadlineNotification = async ( workPackage : WorkPackage ) : Promise < void > => {
30+ export const sendSlackUpcomingDeadlineNotification = async (
31+ workPackage : Prisma . Work_PackageGetPayload < WorkPackageQueryArgs >
32+ ) : Promise < void > => {
2833 if ( process . env . NODE_ENV !== 'production' ) return ; // don't send msgs unless in prod
34+ const endDate = calculateEndDate ( workPackage . startDate , workPackage . duration ) ;
2935
30- const { LEAD_CHANNEL_SLACK_ID } = process . env ;
31- if ( ! LEAD_CHANNEL_SLACK_ID ) return ;
32-
33- const { lead } = workPackage ;
36+ const { lead } = workPackage . wbsElement ;
3437 const slackId = await getUserSlackId ( lead ?. userId ) ;
35- const daysUntilDeadline = daysBetween ( workPackage . endDate , new Date ( ) ) ;
38+ const daysUntilDeadline = daysBetween ( endDate , new Date ( ) ) ;
3639
37- const userString = buildUserString ( lead , slackId ) ;
40+ const userString = lead ? buildUserString ( userTransformer ( lead ) , slackId ) : 'No Lead Set' ;
3841 const dueString = buildDueString ( daysUntilDeadline ) ;
3942
40- const wbsNumber : string = wbsPipe ( workPackage . wbsNum ) ;
43+ const wbsNumber : string = wbsPipe ( workPackage . wbsElement ) ;
4144 const wbsString = `<https://finishlinebyner.com/projects/${ wbsNumber } |${ wbsNumber } >` ;
4245
43- const fullMsg = `${ userString } ${ wbsString } : ${ workPackage . projectName } - ${ workPackage . name } ${ dueString } ` ;
46+ const fullMsg = `${ userString } ${ wbsString } : ${ workPackage . project . wbsElement . name } - ${ workPackage . wbsElement . name } ${ dueString } ` ;
4447
45- await sendMessage ( LEAD_CHANNEL_SLACK_ID , fullMsg ) ;
48+ const promises = workPackage . project . teams . map ( async ( team ) => await sendMessage ( team . slackId , fullMsg ) ) ;
49+
50+ await Promise . all ( promises ) ;
4651} ;
4752
4853/**
0 commit comments