From 547b82f00791d399cc703ad0ac87136402fe797c Mon Sep 17 00:00:00 2001 From: Rowan Date: Mon, 27 Apr 2026 09:01:05 -0500 Subject: [PATCH 1/2] added two layers of task sorting. one at db retrieval and one at the time of sending Co-authored-by: Copilot --- src/backend/src/services/notifications.services.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/src/services/notifications.services.ts b/src/backend/src/services/notifications.services.ts index 9cbd1d6d3c..63c5ac8555 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: { @@ -63,7 +66,7 @@ export default class NotificationsService { const teamTaskMap = new Map(); - // group tasks due by team in a map + // group tasks due by team tasks.forEach((task) => { const teamSlackIds = task.wbsElement.project?.teams.map((team) => team.slackId) ?? []; @@ -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: { From 25134c368501c12cd8328c273c58aef2f045ecf0 Mon Sep 17 00:00:00 2001 From: Rowan Date: Mon, 27 Apr 2026 09:03:20 -0500 Subject: [PATCH 2/2] formatting fix --- src/backend/src/services/notifications.services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/src/services/notifications.services.ts b/src/backend/src/services/notifications.services.ts index 63c5ac8555..cdc7eb5f01 100644 --- a/src/backend/src/services/notifications.services.ts +++ b/src/backend/src/services/notifications.services.ts @@ -66,7 +66,7 @@ export default class NotificationsService { const teamTaskMap = new Map(); - // group tasks due by team + // group tasks due by team in a map tasks.forEach((task) => { const teamSlackIds = task.wbsElement.project?.teams.map((team) => team.slackId) ?? [];