Files
leim-tools/models/CalendarEvent.ts
2025-04-15 15:34:05 +02:00

42 lines
1.1 KiB
TypeScript

import { z } from "zod"
import type { Category } from "./Category"
import { dateSchema, type RPGDate } from "./Date"
export interface CalendarEvent {
id?: number
title: string
location?: string
startDate: RPGDate
endDate?: RPGDate
description?: string
category?: Category
secondaryCategories?: Category[]
hidden?: boolean
wiki?: string
}
/**
* Body validation schema for post requests (insert and update)
*/
export const postEventBodySchema = z.object({
event: z.object({
title: z.string().max(120),
description: z.string().max(1200).optional().nullable(),
location: z.string().max(160).optional().nullable(),
startDate: dateSchema.required(),
endDate: dateSchema.optional().nullable(),
hidden: z.boolean().optional().nullable(),
category: z.object({
id: z.number().int(),
name: z.string(),
color: z.string().default("black")
}).optional().nullable(),
}),
calendarId: z.number({ coerce: true }).int().positive()
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isCalendarEvent(object: any): object is CalendarEvent {
return "startDate" in object
}