Added post component for events

This needs RLS disabled, will work on that later, I don't like postgre
This commit is contained in:
Alexis
2024-06-01 11:07:07 +02:00
parent f2d5277c5f
commit a92edd6215
12 changed files with 474 additions and 100 deletions

View File

@@ -1,8 +1,9 @@
import { z } from 'zod'
import type { Category } from './Category'
import type { RPGDate } from './Date'
import { dateSchema, type RPGDate } from './Date'
export interface CalendarEvent {
id: number
id?: number
title: string
startDate: RPGDate
endDate?: RPGDate
@@ -13,6 +14,19 @@ export interface CalendarEvent {
wiki?: string
}
/**
* Body validation schema for post requests (insert and update)
*/
export const postEventBodySchema = z.object({
event: z.object({
title: z.string(),
description: z.string().optional(),
startDate: dateSchema.required(),
endDate: dateSchema.optional()
}),
calendarId: z.number().int().positive()
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function isCalendarEvent(object: any): object is CalendarEvent {
return 'startDate' in object

View File

@@ -1,3 +1,5 @@
import { z } from "zod"
export interface RPGDate {
day: number
month: number
@@ -6,23 +8,8 @@ export interface RPGDate {
export type RPGDateOrder = 'asc' | 'desc'
// export function getRelativeDate(baseDate: RPGDate, relativeDate: RPGDate) {
// let newDay: number
// let newMonth: number
// let newYear: number
// let newPeriod: RPGPeriod
// const differenceInDays = getDifferenceInDays(baseDate, relativeDate)
// // console.log(baseDate, substractionDate)
// console.log(getRelativeString(baseDate, relativeDate))
// return differenceInDays
// // return {
// // day: newDay,
// // month: newMonth,
// // year: newYear,
// // period: newPeriod
// // }
// }
export const dateSchema = z.object({
day: z.number().int().positive(),
month: z.number().int(),
year: z.number().int()
})