Fix round completion rate: use evaluations/assignments, closed rounds=100%

The round breakdown was showing 200% for active rounds (assignments/projects)
and 0% for closed rounds. Now correctly computes evaluations/assignments for
active rounds and shows 100% for closed/archived rounds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-21 01:34:42 +01:00
parent 350e9b96e8
commit 6d4ee93ab3
2 changed files with 23 additions and 4 deletions

View File

@@ -34,6 +34,10 @@ export const programRouter = router({
_count: {
select: { assignments: true, projectRoundStates: true },
},
assignments: {
where: { evaluation: { status: 'SUBMITTED' } },
select: { id: true },
},
},
},
},
@@ -52,9 +56,11 @@ export const programRouter = router({
// Provide `stages` as alias for backward compatibility
stages: allRounds.map((round: any) => ({
...round,
assignments: undefined, // don't leak raw assignments array
_count: {
projects: round._count?.projectRoundStates || 0,
assignments: round._count?.assignments || 0,
evaluations: round.assignments?.length || 0,
},
})),
// Main rounds array
@@ -68,6 +74,7 @@ export const programRouter = router({
_count: {
projects: round._count?.projectRoundStates || 0,
assignments: round._count?.assignments || 0,
evaluations: round.assignments?.length || 0,
},
})),
}