@@ -44,6 +44,9 @@ export default class NotificationsService {
4444 } ,
4545 dateDeleted : null
4646 } ,
47+ orderBy : {
48+ deadline : 'asc' // earliest (most overdue) first
49+ } ,
4750 include : {
4851 assignees : {
4952 include : {
@@ -63,7 +66,7 @@ export default class NotificationsService {
6366
6467 const teamTaskMap = new Map < string , TaskWithAssignees [ ] > ( ) ;
6568
66- // group tasks due by team in a map
69+ // group tasks due by team
6770 tasks . forEach ( ( task ) => {
6871 const teamSlackIds = task . wbsElement . project ?. teams . map ( ( team ) => team . slackId ) ?? [ ] ;
6972
@@ -78,9 +81,10 @@ export default class NotificationsService {
7881 } ) ;
7982 } ) ;
8083
81- // send the notifications to each team for their respective tasks
84+ // send the notifications to each team for their respective tasks sorted by deadline
8285 const promises = Array . from ( teamTaskMap ) . map ( async ( [ slackId , tasks ] ) => {
8386 const messageBlock = tasks
87+ . sort ( ( a , b ) => a . deadline ! . getTime ( ) - b . deadline ! . getTime ( ) )
8488 . map ( ( task ) => {
8589 // prisma call earlier allows the forced unwrap (deadline is guaranteed to be a non-null value)
8690 const todayMidnightUTC = new Date ( new Date ( ) . setUTCHours ( 0 , 0 , 0 , 0 ) ) ;
@@ -236,7 +240,6 @@ export default class NotificationsService {
236240 static async sendSponsorTaskNotifications ( ) {
237241 const startOfToday = new Date ( new Date ( ) . setUTCHours ( 0 , 0 , 0 , 0 ) ) ;
238242 const endOfToday = startOfDayTomorrow ( ) ;
239-
240243 const sponsorTasks = await prisma . sponsor_Task . findMany ( {
241244 where : {
242245 notifyDate : {
0 commit comments