From f288537c002638584a42d23f92683a2f8ba26556 Mon Sep 17 00:00:00 2001 From: mehallhm Date: Tue, 19 Nov 2024 16:05:34 -0500 Subject: [PATCH 1/3] count only active term notifications --- services/notificationsManager.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/services/notificationsManager.ts b/services/notificationsManager.ts index d4ac4eb2..af1ea9d6 100644 --- a/services/notificationsManager.ts +++ b/services/notificationsManager.ts @@ -15,10 +15,36 @@ class NotificationsManager { async getUserSubscriptions(phoneNumber: string): Promise { const userId = (await prisma.user.findFirst({ where: { phoneNumber } })).id; const followedSections = await prisma.followedSection.findMany({ - where: { userId }, + where: { + userId, + section: { + course: { + termId: { + in: ( + await prisma.termInfo.findMany({ + where: { active: true }, + select: { termId: true }, + }) + ).map((term) => term.termId), + }, + }, + }, + }, }); const followedCourses = await prisma.followedCourse.findMany({ - where: { userId }, + where: { + userId, + course: { + termId: { + in: ( + await prisma.termInfo.findMany({ + where: { active: true }, + select: { termId: true }, + }) + ).map((term) => term.termId), + }, + }, + }, }); return { From d81f230dbed386af79af1039b7082ca66f7f3337 Mon Sep 17 00:00:00 2001 From: mehallhm Date: Tue, 19 Nov 2024 17:09:24 -0500 Subject: [PATCH 2/3] update dbtest --- tests/database/notificationsManager.test.seq.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/database/notificationsManager.test.seq.ts b/tests/database/notificationsManager.test.seq.ts index b2908820..120774ab 100644 --- a/tests/database/notificationsManager.test.seq.ts +++ b/tests/database/notificationsManager.test.seq.ts @@ -53,8 +53,8 @@ describe("user subscriptions", () => { await notifs.putUserSubscriptions(phoneNumber, sectionIds, courseIds); expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({ phoneNumber, - sectionIds, - courseIds, + sectionIds: [], + courseIds: [], }); }); From 541a386d931d2c2113a2e9a23fbf3d93df1495a3 Mon Sep 17 00:00:00 2001 From: mehallhm Date: Tue, 19 Nov 2024 17:13:32 -0500 Subject: [PATCH 3/3] update dbtest --- tests/database/notificationsManager.test.seq.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/database/notificationsManager.test.seq.ts b/tests/database/notificationsManager.test.seq.ts index 120774ab..cbabc437 100644 --- a/tests/database/notificationsManager.test.seq.ts +++ b/tests/database/notificationsManager.test.seq.ts @@ -82,8 +82,8 @@ describe("user subscriptions", () => { expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({ phoneNumber, - sectionIds, - courseIds, + sectionIds: [], + courseIds: [], }); }); @@ -97,7 +97,7 @@ describe("user subscriptions", () => { expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({ phoneNumber, sectionIds: [], - courseIds, + courseIds: [], }); await notifs.deleteAllUserSubscriptions(phoneNumber);