feat: server-side support for advance criterion in upsertForm and submit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 15:08:21 +01:00
parent 0edb50cd3a
commit 6c97ce3ed9

View File

@@ -247,7 +247,7 @@ export const evaluationRouter = router({
if (!scores) return true
const val = scores[c.id]
// Boolean criteria store true/false, numeric criteria store numbers
if (c.type === 'boolean') return typeof val !== 'boolean'
if (c.type === 'boolean' || c.type === 'advance') return typeof val !== 'boolean'
return typeof val !== 'number'
})
if (missingCriteria.length > 0) {
@@ -1255,6 +1255,15 @@ export const evaluationRouter = router({
.mutation(async ({ ctx, input }) => {
const { roundId, criteria } = input
// Enforce max one advance criterion per form
const advanceCount = criteria.filter((c) => c.type === 'advance').length
if (advanceCount > 1) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'Only one advance criterion is allowed per evaluation form',
})
}
// Verify round exists
await ctx.prisma.round.findUniqueOrThrow({ where: { id: roundId } })
@@ -1299,6 +1308,14 @@ export const evaluationRouter = router({
falseLabel: c.falseLabel || 'No',
}
}
if (type === 'advance') {
return {
...base,
required: true, // always required, override any input
trueLabel: c.trueLabel || 'Yes',
falseLabel: c.falseLabel || 'No',
}
}
// section_header
return base
})