Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

count only active term notifications #245

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading