From 98c22251fb0b3466817349f03803be6aa01d4d1f Mon Sep 17 00:00:00 2001 From: Sinclair Chen Date: Fri, 29 Jul 2022 16:49:00 -0700 Subject: [PATCH] Accept string descriptions in market POST api --- docs/docs/api.md | 1 + functions/src/create-contract.ts | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/docs/api.md b/docs/docs/api.md index 85be28ee..a30243e8 100644 --- a/docs/docs/api.md +++ b/docs/docs/api.md @@ -504,6 +504,7 @@ Parameters: - `outcomeType`: Required. One of `BINARY`, `FREE_RESPONSE`, or `NUMERIC`. - `question`: Required. The headline question for the market. - `description`: Required. A long description describing the rules for the market. + - Note: string descriptions do **not** turn into links, mentions, formatted text. Instead, rich text descriptions must be in [TipTap json](https://tiptap.dev/guide/output#option-1-json). - `closeTime`: Required. The time at which the market will close, represented as milliseconds since the epoch. - `tags`: Optional. An array of string tags for the market. diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 786ee8ae..21a9dbbd 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -59,7 +59,7 @@ const descScehma: z.ZodType = z.lazy(() => const bodySchema = z.object({ question: z.string().min(1).max(MAX_QUESTION_LENGTH), - description: descScehma.optional(), + description: descScehma.or(z.string()).optional(), tags: z.array(z.string().min(1).max(MAX_TAG_LENGTH)).optional(), closeTime: zTimestamp().refine( (date) => date.getTime() > new Date().getTime(), @@ -166,13 +166,27 @@ export const createmarket = newEndpoint({}, async (req, auth) => { ante || 0 ) + // convert string descriptions into JSONContent + const newDescription = + typeof description === 'string' + ? { + type: 'doc', + content: [ + { + type: 'paragraph', + content: [{ type: 'text', text: description }], + }, + ], + } + : description ?? {} + const contract = getNewContract( contractRef.id, slug, user, question, outcomeType, - description ?? {}, + newDescription, initialProb ?? 0, ante, closeTime.getTime(),