Added category schema validation
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { z } from 'zod'
|
||||
import type { Category } from './Category'
|
||||
import { categorySchema, type Category } from './Category'
|
||||
import { dateSchema, type RPGDate } from './Date'
|
||||
|
||||
export interface CalendarEvent {
|
||||
@@ -26,9 +26,7 @@ export const postEventBodySchema = z.object({
|
||||
startDate: dateSchema.required(),
|
||||
endDate: dateSchema.optional().nullable(),
|
||||
hidden: z.boolean().optional().nullable(),
|
||||
category: z.object({
|
||||
id: z.number().int()
|
||||
}),
|
||||
category: categorySchema.optional().nullable(),
|
||||
}),
|
||||
calendarId: z.number({ coerce: true }).int().positive()
|
||||
})
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export interface Category {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export const categorySchema = z.object({
|
||||
id: z.number().int(),
|
||||
name: z.string()
|
||||
})
|
||||
|
||||
@@ -41,7 +41,7 @@ export default defineEventHandler(async (event) => {
|
||||
description: bodyData.event.description,
|
||||
location: bodyData.event.location,
|
||||
hidden: bodyData.event.hidden,
|
||||
category: bodyData.event.category.id,
|
||||
category: bodyData.event.category?.id,
|
||||
calendar_id: bodyData?.calendarId
|
||||
} as never
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ export default defineEventHandler(async (event) => {
|
||||
description: bodyData.event.description,
|
||||
location: bodyData.event.location,
|
||||
hidden: bodyData.event.hidden,
|
||||
category: bodyData.event.category.id,
|
||||
category: bodyData.event.category?.id,
|
||||
calendar_id: bodyData?.calendarId
|
||||
} as never
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user