Skip to content

Commit

Permalink
Refactor scenario schema with zod
Browse files Browse the repository at this point in the history
  • Loading branch information
mikucat0309 committed Nov 24, 2023
1 parent c7409b4 commit 6eaf555
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions api/schema/scenario.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { LocalizedText } from './localized'
import { AttendeeMetadata } from './attendee'
import { localizedTextSchema } from './localized'
import { attendeeMetadataSchema } from './attendee'
import { Path, Str } from '@cloudflare/itty-router-openapi'
import { z } from 'zod'

export const ScenarioIdPath = Path(Str, { description: 'scenarion name to apply' })

export type Scenario = {
order: number
available_time: number | null
expire_time: number | null
display_text: LocalizedText
used: number | null
disabled: string | null
attr: AttendeeMetadata
}
export type Scenario = z.infer<typeof scenarioSchema>
export const scenarioSchema = z.object({
order: z.number().describe('display order').default(1),
available_time: z.number().nullable().describe('timestamp').default(1600000000),
expire_time: z.number().nullable().describe('timestamp').default(1700000000),
display_text: localizedTextSchema,
used: z.number().nullable().describe('timestamp').default(1650000000),
disabled: z.string().nullable(),
attr: attendeeMetadataSchema,
})

0 comments on commit 6eaf555

Please sign in to comment.