Round system redesign: Phases 1-7 complete

Full pipeline/track/stage architecture replacing the legacy round system.

Schema: 11 new models (Pipeline, Track, Stage, StageTransition,
ProjectStageState, RoutingRule, Cohort, CohortProject, LiveProgressCursor,
OverrideAction, AudienceVoter) + 8 new enums.

Backend: 9 new routers (pipeline, stage, routing, stageFiltering,
stageAssignment, cohort, live, decision, award) + 6 new services
(stage-engine, routing-engine, stage-filtering, stage-assignment,
stage-notifications, live-control).

Frontend: Pipeline wizard (17 components), jury stage pages (7),
applicant pipeline pages (3), public stage pages (2), admin pipeline
pages (5), shared stage components (3), SSE route, live hook.

Phase 6 refit: 23 routers/services migrated from roundId to stageId,
all frontend components refitted. Deleted round.ts (985 lines),
roundTemplate.ts, round-helpers.ts, round-settings.ts, round-type-settings.tsx,
10 legacy admin pages, 7 legacy jury pages, 3 legacy dialogs.

Phase 7 validation: 36 tests (10 unit + 8 integration files) all passing,
TypeScript 0 errors, Next.js build succeeds, 13 integrity checks,
legacy symbol sweep clean, auto-seed on first Docker startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 13:57:09 +01:00
parent 8a328357e3
commit 331b67dae0
256 changed files with 29117 additions and 21424 deletions

View File

@@ -3,24 +3,34 @@ import { TRPCError } from '@trpc/server'
import { randomUUID } from 'crypto'
import { router, protectedProcedure, adminProcedure, publicProcedure } from '../trpc'
import { logAudit } from '../utils/audit'
import type { LiveVotingCriterion } from '@/types/round-settings'
interface LiveVotingCriterion {
id: string
label: string
description?: string
scale: number
weight: number
}
export const liveVotingRouter = router({
/**
* Get or create a live voting session for a round
* Get or create a live voting session for a stage
*/
getSession: adminProcedure
.input(z.object({ roundId: z.string() }))
.input(z.object({ stageId: z.string() }))
.query(async ({ ctx, input }) => {
let session = await ctx.prisma.liveVotingSession.findUnique({
where: { roundId: input.roundId },
where: { stageId: input.stageId },
include: {
round: {
stage: {
include: {
program: { select: { name: true, year: true } },
projects: {
where: { status: { in: ['FINALIST', 'SEMIFINALIST'] } },
select: { id: true, title: true, teamName: true },
track: {
include: {
pipeline: {
include: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
@@ -28,18 +38,21 @@ export const liveVotingRouter = router({
})
if (!session) {
// Create session
session = await ctx.prisma.liveVotingSession.create({
data: {
roundId: input.roundId,
stageId: input.stageId,
},
include: {
round: {
stage: {
include: {
program: { select: { name: true, year: true } },
projects: {
where: { status: { in: ['FINALIST', 'SEMIFINALIST'] } },
select: { id: true, title: true, teamName: true },
track: {
include: {
pipeline: {
include: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
@@ -81,15 +94,22 @@ export const liveVotingRouter = router({
const session = await ctx.prisma.liveVotingSession.findUniqueOrThrow({
where: { id: input.sessionId },
include: {
round: {
stage: {
include: {
program: { select: { name: true, year: true } },
track: {
include: {
pipeline: {
include: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
},
})
// Get current project if in progress
let currentProject = null
if (session.currentProjectId && session.status === 'IN_PROGRESS') {
currentProject = await ctx.prisma.project.findUnique({
@@ -98,7 +118,6 @@ export const liveVotingRouter = router({
})
}
// Get user's vote for current project
let userVote = null
if (session.currentProjectId) {
userVote = await ctx.prisma.liveVote.findFirst({
@@ -110,7 +129,6 @@ export const liveVotingRouter = router({
})
}
// Calculate time remaining
let timeRemaining = null
if (session.votingEndsAt && session.status === 'IN_PROGRESS') {
const remaining = new Date(session.votingEndsAt).getTime() - Date.now()
@@ -126,7 +144,7 @@ export const liveVotingRouter = router({
votingMode: session.votingMode,
criteriaJson: session.criteriaJson,
},
round: session.round,
stage: session.stage,
currentProject,
userVote,
timeRemaining,
@@ -142,27 +160,32 @@ export const liveVotingRouter = router({
const session = await ctx.prisma.liveVotingSession.findUniqueOrThrow({
where: { id: input.sessionId },
include: {
round: {
stage: {
include: {
program: { select: { name: true, year: true } },
track: {
include: {
pipeline: {
include: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
},
})
// Get all projects in order
const projectOrder = (session.projectOrderJson as string[]) || []
const projects = await ctx.prisma.project.findMany({
where: { id: { in: projectOrder } },
select: { id: true, title: true, teamName: true },
})
// Sort by order
const sortedProjects = projectOrder
.map((id) => projects.find((p) => p.id === id))
.filter(Boolean)
// Get scores for each project
const scores = await ctx.prisma.liveVote.groupBy({
by: ['projectId'],
where: { sessionId: session.id },
@@ -186,7 +209,7 @@ export const liveVotingRouter = router({
currentProjectId: session.currentProjectId,
votingEndsAt: session.votingEndsAt,
},
round: session.round,
stage: session.stage,
projects: projectsWithScores,
}
}),
@@ -546,9 +569,17 @@ export const liveVotingRouter = router({
const session = await ctx.prisma.liveVotingSession.findUniqueOrThrow({
where: { id: input.sessionId },
include: {
round: {
stage: {
include: {
program: { select: { name: true, year: true } },
track: {
include: {
pipeline: {
include: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
},
@@ -898,10 +929,18 @@ export const liveVotingRouter = router({
audienceVotingMode: true,
audienceRequireId: true,
audienceMaxFavorites: true,
round: {
stage: {
select: {
name: true,
program: { select: { name: true, year: true } },
track: {
select: {
pipeline: {
select: {
program: { select: { name: true, year: true } },
},
},
},
},
},
},
},