wip Fix API validation

This commit is contained in:
Sinclair Chen 2022-06-28 18:08:57 -05:00
parent 5b29d32cfa
commit 0d101d4237
3 changed files with 29 additions and 4 deletions

View File

@ -23,6 +23,8 @@
"main": "functions/src/index.js",
"dependencies": {
"@amplitude/node": "1.10.0",
"@tiptap/core": "^2.0.0-beta.181",
"@tiptap/starter-kit": "^2.0.0-beta.190",
"fetch": "1.1.0",
"firebase-admin": "10.0.0",
"firebase-functions": "3.21.2",

View File

@ -5,7 +5,6 @@ import {
CPMMBinaryContract,
Contract,
FreeResponseContract,
MAX_DESCRIPTION_LENGTH,
MAX_QUESTION_LENGTH,
MAX_TAG_LENGTH,
NumericContract,
@ -28,10 +27,34 @@ import { getNewContract } from '../../common/new-contract'
import { NUMERIC_BUCKET_COUNT } from '../../common/numeric-constants'
import { User } from '../../common/user'
import { Group, MAX_ID_LENGTH } from '../../common/group'
import { JSONContent } from '@tiptap/core'
const descScehma: z.ZodType<JSONContent> = z.lazy(() =>
z.intersection(
z.record(z.any()),
z.object({
type: z.string().optional(),
attrs: z.record(z.any()).optional(),
content: z.array(descScehma).optional(),
marks: z
.array(
z.intersection(
z.record(z.any()),
z.object({
type: z.string(),
attrs: z.record(z.any()).optional(),
})
)
)
.optional(),
text: z.string().optional(),
})
)
)
const bodySchema = z.object({
question: z.string().min(1).max(MAX_QUESTION_LENGTH),
description: z.string().max(MAX_DESCRIPTION_LENGTH),
description: descScehma.optional(),
tags: z.array(z.string().min(1).max(MAX_TAG_LENGTH)).optional(),
closeTime: zTimestamp().refine(
(date) => date.getTime() > new Date().getTime(),
@ -114,7 +137,7 @@ export const createmarket = newEndpoint(['POST'], async (req, auth) => {
user,
question,
outcomeType,
description,
description ?? {},
initialProb ?? 0,
ante,
closeTime.getTime(),

View File

@ -2,7 +2,7 @@ import * as functions from 'firebase-functions'
import { getUser } from './utils'
import { createNotification } from './create-notification'
import { Contract } from '../../common/contract'
import { richTextToString } from 'common/util/parse'
import { richTextToString } from '../../common/util/parse'
export const onCreateContract = functions.firestore
.document('contracts/{contractId}')