Files
Calbook/lib/validators/admin.ts

55 lines
1.5 KiB
TypeScript

import { z } from "zod";
import { SETTING_KEYS } from "@/lib/constants";
const ALLOWED_SETTING_KEYS = new Set<string>(Object.values(SETTING_KEYS));
export const upsertStaffSchema = z.object({
name: z.string().min(2),
email: z.string().email(),
password: z.string().min(8).optional(),
role: z.enum(["ADMIN", "STAFF"]).default("STAFF"),
slug: z
.string()
.min(2)
.regex(/^[a-z0-9-]+$/),
bio: z.string().max(500).optional(),
avatarUrl: z.string().url().optional().or(z.literal("")),
isActive: z.boolean().default(true)
});
export const settingsSchema = z
.object({
values: z.record(z.string().max(100), z.string().max(250_000))
})
.superRefine((input, ctx) => {
const keys = Object.keys(input.values);
if (keys.length > 200) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Zu viele Einstellungen in einem Request.",
path: ["values"]
});
return;
}
for (const key of keys) {
if (!ALLOWED_SETTING_KEYS.has(key)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Unbekannter Einstellungsschlüssel: ${key}`,
path: ["values", key]
});
}
}
});
export const appointmentsFilterSchema = z.object({
mitarbeiterId: z.string().optional(),
status: z.enum(["CONFIRMED", "CANCELLED"]).optional(),
noShow: z.enum(["true", "false"]).optional(),
q: z.string().optional(),
von: z.string().optional(),
bis: z.string().optional()
});