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