more validation for creating numeric markets
This commit is contained in:
parent
7b60cc63ce
commit
61300e93a4
|
@ -46,7 +46,8 @@ const binarySchema = z.object({
|
||||||
initialProb: z.number().min(1).max(99),
|
initialProb: z.number().min(1).max(99),
|
||||||
})
|
})
|
||||||
|
|
||||||
const finite = () => z.number().gte(Number.MIN_SAFE_INTEGER).lte(Number.MAX_SAFE_INTEGER)
|
const finite = () =>
|
||||||
|
z.number().gte(Number.MIN_SAFE_INTEGER).lte(Number.MAX_SAFE_INTEGER)
|
||||||
|
|
||||||
const numericSchema = z.object({
|
const numericSchema = z.object({
|
||||||
min: finite(),
|
min: finite(),
|
||||||
|
@ -67,10 +68,13 @@ export const createmarket = newEndpoint({}, async (req, auth) => {
|
||||||
numericSchema,
|
numericSchema,
|
||||||
req.body
|
req.body
|
||||||
))
|
))
|
||||||
if (max - min <= 0.01 || initialValue < min || initialValue > max)
|
if (max - min <= 0.01 || initialValue <= min || initialValue >= max)
|
||||||
throw new APIError(400, 'Invalid range.')
|
throw new APIError(400, 'Invalid range.')
|
||||||
|
|
||||||
initialProb = getPseudoProbability(initialValue, min, max, isLogScale) * 100
|
initialProb = getPseudoProbability(initialValue, min, max, isLogScale) * 100
|
||||||
|
|
||||||
|
if (initialProb < 1 || initialProb > 99)
|
||||||
|
throw new APIError(400, 'Invalid initial value.')
|
||||||
}
|
}
|
||||||
if (outcomeType === 'BINARY') {
|
if (outcomeType === 'BINARY') {
|
||||||
;({ initialProb } = validate(binarySchema, req.body))
|
;({ initialProb } = validate(binarySchema, req.body))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user