Skip to content

Commit 4285509

Browse files
committed
fix: fix several cases of cursus users only being considered active when no end date is set
1 parent ed780c8 commit 4285509

File tree

6 files changed

+45
-23
lines changed

6 files changed

+45
-23
lines changed

src/handlers/points.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ export const createScore = async function(prisma: PrismaClient, type: CodamCoali
3333
},
3434
cursus_users: {
3535
where: { // only get active cursus_users for the relevant cursus
36-
OR: [
36+
AND: [
3737
{
3838
cursus_id: CURSUS_ID,
39-
end_at: null,
4039
},
4140
{
42-
cursus_id: CURSUS_ID,
43-
end_at: {
44-
gt: scoreDate, // also consider cursus_users that were still active at the score creation date
45-
},
41+
OR: [
42+
{ end_at: null },
43+
{ end_at: { gt: scoreDate } }, // also consider cursus_users that were still active at the score creation date
44+
],
4645
},
4746
],
4847
},

src/routes/admin/apisearcher.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,10 @@ export const setupAPISearchRoutes = function(app: Express, prisma: PrismaClient)
525525
cursus_users: {
526526
some: {
527527
cursus_id: CURSUS_ID,
528-
end_at: null,
528+
OR: [
529+
{ end_at: null },
530+
{ end_at: { gt: new Date() } }, // also consider cursus_users that are still active
531+
],
529532
},
530533
},
531534
},

src/routes/admin/charts.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ export const setupAdminChartsRoutes = function(app: Express, prisma: PrismaClien
2727
cursus_users: {
2828
some: {
2929
cursus_id: CURSUS_ID,
30-
end_at: null,
31-
}
32-
}
33-
}
30+
OR: [
31+
{ end_at: null },
32+
{ end_at: { gt: new Date() } }, // also consider cursus_users that are still active at the current date
33+
],
34+
},
35+
},
36+
},
3437
},
3538
orderBy: {
3639
_count: {
@@ -64,7 +67,10 @@ export const setupAdminChartsRoutes = function(app: Express, prisma: PrismaClien
6467
cursus_users: {
6568
some: {
6669
cursus_id: CURSUS_ID,
67-
end_at: null,
70+
OR: [
71+
{ end_at: null },
72+
{ end_at: { gt: new Date() } }, // also consider cursus_users that are still active at the current date
73+
],
6874
},
6975
},
7076
},

src/routes/coalitions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ export const setupCoalitionRoutes = function(app: Express, prisma: PrismaClient)
3939
},
4040
cursus_users: {
4141
some: {
42-
end_at: null, // Make sure to only get active staff members
42+
OR: [
43+
{ end_at: null },
44+
{ end_at: { gt: now } }, // also consider cursus_users that are still active
45+
],
4346
},
4447
},
4548
},

src/routes/quiz.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,15 @@ export const isQuizAvailable = async function(user: IntraUser | ExpressIntraUser
7373
},
7474
cursus_users: {
7575
where: {
76-
OR: [ // only consider active cursus users for the relevant cursus
76+
AND: [ // only consider active cursus users for the relevant cursus
7777
{
7878
cursus_id: CURSUS_ID,
79-
end_at: null,
8079
},
8180
{
82-
cursus_id: CURSUS_ID,
83-
end_at: {
84-
gt: currentDate, // also consider cursus_users that are still active at the current date
85-
},
81+
OR: [
82+
{ end_at: null },
83+
{ end_at: { gt: currentDate } }, // also consider cursus_users that are still active at the current date
84+
],
8685
},
8786
],
8887
},

src/utils.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,18 @@ export const isStudent = async function(prisma: PrismaClient, intraUser: Express
6666
// Or the student is not a part of the campus the coalition system is part of.
6767
const cursusUser = await prisma.intraCursusUser.findFirst({
6868
where: {
69-
user_id: userId,
70-
cursus_id: CURSUS_ID,
71-
end_at: null,
69+
AND: [
70+
{
71+
user_id: userId,
72+
cursus_id: CURSUS_ID,
73+
},
74+
{
75+
OR: [
76+
{ end_at: null },
77+
{ end_at: { gt: new Date() } }, // also consider cursus_users that were still active at the score creation date
78+
],
79+
},
80+
],
7281
},
7382
});
7483
return (cursusUser !== null);
@@ -524,7 +533,10 @@ export const getCoalitionScore = async function(prisma: PrismaClient, coalitionI
524533
cursus_users: {
525534
some: {
526535
cursus_id: CURSUS_ID,
527-
end_at: null,
536+
OR: [
537+
{ end_at: null },
538+
{ end_at: { gt: atDateTime } }, // also consider cursus_users that were still active at the score creation date
539+
],
528540
}
529541
}
530542
},

0 commit comments

Comments
 (0)