Files
MOPC-Portal/src/server/routers/resultLock.ts
Matt 6ca39c976b
All checks were successful
Build and Push Docker Image / build (push) Successful in 7m45s
Competition/Round architecture: full platform rewrite (Phases 1-9)
Replace Pipeline/Stage system with Competition/Round architecture.
New schema: Competition, Round (7 types), JuryGroup, AssignmentPolicy,
ProjectRoundState, DeliberationSession, ResultLock, SubmissionWindow.
New services: round-engine, round-assignment, deliberation, result-lock,
submission-manager, competition-context, ai-prompt-guard.
Full admin/jury/applicant/mentor UI rewrite. AI prompt hardening with
structured prompts, retry logic, and injection detection. All legacy
pipeline/stage code removed. 4 new migrations + seed aligned.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 23:04:15 +01:00

101 lines
2.4 KiB
TypeScript

import { z } from 'zod'
import { TRPCError } from '@trpc/server'
import { router, adminProcedure, superAdminProcedure, protectedProcedure } from '../trpc'
import {
lockResults,
unlockResults,
isLocked,
getLockHistory,
} from '../services/result-lock'
const categoryEnum = z.enum([
'STARTUP',
'BUSINESS_CONCEPT',
])
export const resultLockRouter = router({
/**
* Lock results for a competition/round/category (admin)
*/
lock: adminProcedure
.input(
z.object({
competitionId: z.string(),
roundId: z.string(),
category: categoryEnum,
resultSnapshot: z.unknown(),
})
)
.mutation(async ({ ctx, input }) => {
const result = await lockResults(
{
competitionId: input.competitionId,
roundId: input.roundId,
category: input.category,
lockedById: ctx.user.id,
resultSnapshot: input.resultSnapshot,
},
ctx.prisma,
)
if (!result.success) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: result.errors?.join('; ') ?? 'Failed to lock results',
})
}
return result
}),
/**
* Unlock results (super-admin only)
*/
unlock: superAdminProcedure
.input(
z.object({
resultLockId: z.string(),
reason: z.string().min(1).max(2000),
})
)
.mutation(async ({ ctx, input }) => {
const result = await unlockResults(
{
resultLockId: input.resultLockId,
unlockedById: ctx.user.id,
reason: input.reason,
},
ctx.prisma,
)
if (!result.success) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: result.errors?.join('; ') ?? 'Failed to unlock results',
})
}
return result
}),
/**
* Check if results are locked
*/
isLocked: protectedProcedure
.input(
z.object({
competitionId: z.string(),
roundId: z.string(),
category: categoryEnum,
})
)
.query(async ({ ctx, input }) => {
return isLocked(input.competitionId, input.roundId, input.category, ctx.prisma)
}),
/**
* Get lock history for a competition
*/
history: adminProcedure
.input(z.object({ competitionId: z.string() }))
.query(async ({ ctx, input }) => {
return getLockHistory(input.competitionId, ctx.prisma)
}),
})