Decouple projects from rounds with RoundProject join table

Projects now exist at the program level instead of being locked to a
single round. A new RoundProject join table enables many-to-many
relationships with per-round status tracking. Rounds have sortOrder
for configurable progression paths.

- Add RoundProject model, programId on Project, sortOrder on Round
- Migration preserves existing data (roundId -> RoundProject entries)
- Update all routers to query through RoundProject join
- Add assign/remove/advance/reorder round endpoints
- Add Assign, Advance, Remove Projects dialogs on round detail page
- Add round reorder controls (up/down arrows) on rounds list
- Show all rounds on project detail page

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-02 22:33:55 +01:00
parent 0d2bc4db7e
commit fd5e5222da
52 changed files with 1892 additions and 326 deletions

View File

@@ -148,13 +148,17 @@ export const analyticsRouter = router({
getProjectRankings: adminProcedure
.input(z.object({ roundId: z.string(), limit: z.number().optional() }))
.query(async ({ ctx, input }) => {
const projects = await ctx.prisma.project.findMany({
const roundProjects = await ctx.prisma.roundProject.findMany({
where: { roundId: input.roundId },
include: {
assignments: {
project: {
include: {
evaluation: {
select: { criterionScoresJson: true, status: true },
assignments: {
include: {
evaluation: {
select: { criterionScoresJson: true, status: true },
},
},
},
},
},
@@ -162,8 +166,9 @@ export const analyticsRouter = router({
})
// Calculate average scores
const rankings = projects
.map((project) => {
const rankings = roundProjects
.map((rp) => {
const project = rp.project
const allScores: number[] = []
project.assignments.forEach((assignment) => {
@@ -195,7 +200,7 @@ export const analyticsRouter = router({
id: project.id,
title: project.title,
teamName: project.teamName,
status: project.status,
status: rp.status,
averageScore,
evaluationCount: allScores.length,
}
@@ -212,15 +217,15 @@ export const analyticsRouter = router({
getStatusBreakdown: adminProcedure
.input(z.object({ roundId: z.string() }))
.query(async ({ ctx, input }) => {
const projects = await ctx.prisma.project.groupBy({
const roundProjects = await ctx.prisma.roundProject.groupBy({
by: ['status'],
where: { roundId: input.roundId },
_count: true,
})
return projects.map((p) => ({
status: p.status,
count: p._count,
return roundProjects.map((rp) => ({
status: rp.status,
count: rp._count,
}))
}),
@@ -237,7 +242,7 @@ export const analyticsRouter = router({
jurorCount,
statusCounts,
] = await Promise.all([
ctx.prisma.project.count({ where: { roundId: input.roundId } }),
ctx.prisma.roundProject.count({ where: { roundId: input.roundId } }),
ctx.prisma.assignment.count({ where: { roundId: input.roundId } }),
ctx.prisma.evaluation.count({
where: {
@@ -249,7 +254,7 @@ export const analyticsRouter = router({
by: ['userId'],
where: { roundId: input.roundId },
}),
ctx.prisma.project.groupBy({
ctx.prisma.roundProject.groupBy({
by: ['status'],
where: { roundId: input.roundId },
_count: true,
@@ -348,8 +353,8 @@ export const analyticsRouter = router({
)
.query(async ({ ctx, input }) => {
const where = input.roundId
? { roundId: input.roundId }
: { round: { programId: input.programId } }
? { roundProjects: { some: { roundId: input.roundId } } }
: { programId: input.programId }
const distribution = await ctx.prisma.project.groupBy({
by: ['country'],