Added category schema validation

This commit is contained in:
Alexis
2024-06-10 20:43:05 +02:00
parent a1aa512018
commit 69f18e9338
4 changed files with 11 additions and 6 deletions

View File

@@ -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()
})

View File

@@ -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()
})

View File

@@ -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
)

View File

@@ -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
)