Skip to content

Commit

Permalink
Count only active term notifications for limit (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
mehallhm authored Nov 19, 2024
1 parent a5d14a0 commit e05fc90
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
30 changes: 28 additions & 2 deletions services/notificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,36 @@ class NotificationsManager {
async getUserSubscriptions(phoneNumber: string): Promise<UserInfo> {
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 {
Expand Down
10 changes: 5 additions & 5 deletions tests/database/notificationsManager.test.seq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe("user subscriptions", () => {
await notifs.putUserSubscriptions(phoneNumber, sectionIds, courseIds);
expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({
phoneNumber,
sectionIds,
courseIds,
sectionIds: [],
courseIds: [],
});
});

Expand Down Expand Up @@ -82,8 +82,8 @@ describe("user subscriptions", () => {

expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({
phoneNumber,
sectionIds,
courseIds,
sectionIds: [],
courseIds: [],
});
});

Expand All @@ -97,7 +97,7 @@ describe("user subscriptions", () => {
expect(await notifs.getUserSubscriptions(phoneNumber)).toEqual({
phoneNumber,
sectionIds: [],
courseIds,
courseIds: [],
});

await notifs.deleteAllUserSubscriptions(phoneNumber);
Expand Down

0 comments on commit e05fc90

Please sign in to comment.