From 3b11af61b55f0cdb7ec4520943b9f48d72d5ea0d Mon Sep 17 00:00:00 2001 From: Mikucat Date: Fri, 24 Nov 2023 17:39:16 +0800 Subject: [PATCH] Refactor status schema with zod --- api/schema/status.ts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/api/schema/status.ts b/api/schema/status.ts index ae84778..31e505b 100644 --- a/api/schema/status.ts +++ b/api/schema/status.ts @@ -1,12 +1,14 @@ -import { Scenario } from './scenario' -import { AttendeeMetadata } from './attendee' +import { scenarioSchema } from './scenario' +import { attendeeMetadataSchema } from './attendee' +import { z } from 'zod' -export type Status = { - event_id: string - public_token: string - user_id: string - first_use: number | null - role: string - scenario: Record - attr: AttendeeMetadata -} +export type Status = z.infer +export const statusSchema = z.object({ + event_id: z.string().default('COSCUP_2023'), + public_token: z.string().default('8b1619a7-347c-477a-9045-e48a7828a235'), + user_id: z.string().default('user1234'), + first_use: z.number().nullable().describe('timestamp').default(1650000000), + role: z.string().default('audience'), + scenario: z.record(scenarioSchema).describe('Scenario ID => Scenario'), + attr: attendeeMetadataSchema, +})