diff --git a/src/backend/src/services/notifications.services.ts b/src/backend/src/services/notifications.services.ts index 9cbd1d6d3c..cdc7eb5f01 100644 --- a/src/backend/src/services/notifications.services.ts +++ b/src/backend/src/services/notifications.services.ts @@ -44,6 +44,9 @@ export default class NotificationsService { }, dateDeleted: null }, + orderBy: { + deadline: 'asc' // earliest (most overdue) first + }, include: { assignees: { include: { @@ -78,9 +81,10 @@ export default class NotificationsService { }); }); - // send the notifications to each team for their respective tasks + // send the notifications to each team for their respective tasks sorted by deadline const promises = Array.from(teamTaskMap).map(async ([slackId, tasks]) => { const messageBlock = tasks + .sort((a, b) => a.deadline!.getTime() - b.deadline!.getTime()) .map((task) => { // prisma call earlier allows the forced unwrap (deadline is guaranteed to be a non-null value) const todayMidnightUTC = new Date(new Date().setUTCHours(0, 0, 0, 0)); @@ -236,7 +240,6 @@ export default class NotificationsService { static async sendSponsorTaskNotifications() { const startOfToday = new Date(new Date().setUTCHours(0, 0, 0, 0)); const endOfToday = startOfDayTomorrow(); - const sponsorTasks = await prisma.sponsor_Task.findMany({ where: { notifyDate: {