Validate lowLimitProb < highLimitProb

This commit is contained in:
James Grugett 2022-07-18 19:17:04 -05:00
parent 30b95d75d9
commit c261fc2743

View File

@ -29,7 +29,8 @@ const bodySchema = z.object({
amount: z.number().gte(1), amount: z.number().gte(1),
}) })
const binarySchema = z.union([ const binarySchema = z
.union([
z.object({ z.object({
outcome: z.enum(['YES', 'NO']), outcome: z.enum(['YES', 'NO']),
limitProb: z.number().gte(0.001).lte(0.999).optional(), limitProb: z.number().gte(0.001).lte(0.999).optional(),
@ -38,7 +39,16 @@ const binarySchema = z.union([
lowLimitProb: z.number().gte(0.001).lte(0.999), lowLimitProb: z.number().gte(0.001).lte(0.999),
highLimitProb: z.number().gte(0.001).lte(0.999), highLimitProb: z.number().gte(0.001).lte(0.999),
}), }),
]) ])
.superRefine((data, ctx) => {
if ('lowLimitProb' in data && data.lowLimitProb >= data.highLimitProb) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ['lowLimitProb'],
message: 'lowLimitProb should be less than highLimitProb',
})
}
})
const freeResponseSchema = z.object({ const freeResponseSchema = z.object({
outcome: z.string(), outcome: z.string(),