Skip to content

Commit 610714d

Browse files
committed
Better current phase matching for multiple active phases (PM-2207)
1 parent 6c8470f commit 610714d

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/services/ChallengeService.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,24 @@ async function searchChallenges(currentUser, criteria) {
648648
});
649649
}
650650
if (criteria.currentPhaseName) {
651-
if (criteria.currentPhaseName === "Registration") {
652-
prismaFilter.where.AND.push({
653-
currentPhaseNames: { hasSome: ["Registration", "Open"] },
654-
});
655-
} else {
656-
prismaFilter.where.AND.push({
657-
currentPhaseNames: { has: criteria.currentPhaseName },
658-
});
659-
}
651+
const phaseNamesToMatch =
652+
criteria.currentPhaseName === "Registration"
653+
? ["Registration", "Open"]
654+
: [criteria.currentPhaseName];
655+
656+
prismaFilter.where.AND.push({
657+
OR: [
658+
{ currentPhaseNames: { hasSome: phaseNamesToMatch } },
659+
{
660+
phases: {
661+
some: {
662+
name: { in: phaseNamesToMatch },
663+
isOpen: true,
664+
},
665+
},
666+
},
667+
],
668+
});
660669
}
661670
if (criteria.createdDateStart) {
662671
prismaFilter.where.AND.push({

0 commit comments

Comments
 (0)