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:
@@ -247,7 +247,7 @@ export const evaluationRouter = router({
|
|||||||
if (!scores) return true
|
if (!scores) return true
|
||||||
const val = scores[c.id]
|
const val = scores[c.id]
|
||||||
// Boolean criteria store true/false, numeric criteria store numbers
|
// 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'
|
return typeof val !== 'number'
|
||||||
})
|
})
|
||||||
if (missingCriteria.length > 0) {
|
if (missingCriteria.length > 0) {
|
||||||
@@ -1255,6 +1255,15 @@ export const evaluationRouter = router({
|
|||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { roundId, criteria } = 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
|
// Verify round exists
|
||||||
await ctx.prisma.round.findUniqueOrThrow({ where: { id: roundId } })
|
await ctx.prisma.round.findUniqueOrThrow({ where: { id: roundId } })
|
||||||
|
|
||||||
@@ -1299,6 +1308,14 @@ export const evaluationRouter = router({
|
|||||||
falseLabel: c.falseLabel || 'No',
|
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
|
// section_header
|
||||||
return base
|
return base
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user