diff --git a/src/server/routers/applicant.ts b/src/server/routers/applicant.ts index cc61c08..c16ad56 100644 --- a/src/server/routers/applicant.ts +++ b/src/server/routers/applicant.ts @@ -1431,15 +1431,17 @@ export const applicantRouter = router({ })).map((prs) => prs.roundId) ) - const closedEvalRounds = await ctx.prisma.round.findMany({ - where: { - competition: { programId: project.programId }, - roundType: 'EVALUATION', - status: { in: ['ROUND_CLOSED', 'ROUND_ARCHIVED'] }, - ...(projectRoundIds.size > 0 ? { id: { in: [...projectRoundIds] } } : {}), - }, - select: { configJson: true }, - }) + const closedEvalRounds = projectRoundIds.size > 0 + ? await ctx.prisma.round.findMany({ + where: { + competition: { programId: project.programId }, + roundType: 'EVALUATION', + status: { in: ['ROUND_CLOSED', 'ROUND_ARCHIVED'] }, + id: { in: [...projectRoundIds] }, + }, + select: { configJson: true }, + }) + : [] hasEvaluationRounds = closedEvalRounds.some((r) => { const parsed = EvaluationConfigSchema.safeParse(r.configJson) return parsed.success && parsed.data.applicantVisibility.enabled @@ -1713,12 +1715,14 @@ export const applicantRouter = router({ })).map((prs) => prs.roundId) ) + if (projectRoundIds.size === 0) return [] + const evalRounds = await ctx.prisma.round.findMany({ where: { competition: { programId: project.programId }, roundType: 'EVALUATION', status: { in: ['ROUND_CLOSED', 'ROUND_ARCHIVED'] }, - ...(projectRoundIds.size > 0 ? { id: { in: [...projectRoundIds] } } : {}), + id: { in: [...projectRoundIds] }, }, select: { id: true, @@ -1828,15 +1832,12 @@ export const applicantRouter = router({ }) // Filter by award track membership - const projectRoundIds = new Set( - (await ctx.prisma.projectRoundState.findMany({ - where: { projectId: project.id }, - select: { roundId: true }, - })).map((prs) => prs.roundId) - ) - const isInAwardTrack = rounds.some( - (r) => r.specialAwardId && projectRoundIds.has(r.id) - ) + const projectStates = await ctx.prisma.projectRoundState.findMany({ + where: { projectId: project.id }, + select: { roundId: true, round: { select: { specialAwardId: true } } }, + }) + const projectRoundIds = new Set(projectStates.map((prs) => prs.roundId)) + const isInAwardTrack = projectStates.some((prs) => prs.round.specialAwardId) return rounds .filter((r) => {