This commit is contained in:
1 parent
8efd032cc6
commit
df38dccbf1
735 files changed
+128321
-120870
No files matched your search
+50
-34
@@ -4,51 +4,67 @@ import { z } from "zod";
|
||||
const emptyToUndefined = (v: unknown) => (v === "" ? undefined : v);
|
||||
|
||||
export const eventTypeSchema = z.object({
|
||||
name: z.string().min(1, "Name is required").max(100),
|
||||
slug: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(100)
|
||||
.regex(/^[a-z0-9-]+$/, "Slug must be lowercase with hyphens"),
|
||||
description: z.string().max(500).optional().default(""),
|
||||
color: z.string().max(20).optional().default("#3b82f6"),
|
||||
icon: z.string().max(50).optional().default("calendar"),
|
||||
isActive: z.coerce.number().int().min(0).max(1).default(1),
|
||||
minRank: z.coerce.number().int().min(0).max(7).default(0),
|
||||
name: z.string().min(1, "Name is required").max(100),
|
||||
slug: z
|
||||
.string()
|
||||
.min(1)
|
||||
.max(100)
|
||||
.regex(/^[a-z0-9-]+$/, "Slug must be lowercase with hyphens"),
|
||||
description: z.string().max(500).optional().default(""),
|
||||
color: z.string().max(20).optional().default("#3b82f6"),
|
||||
icon: z.string().max(50).optional().default("calendar"),
|
||||
isActive: z.coerce.number().int().min(0).max(1).default(1),
|
||||
minRank: z.coerce.number().int().min(0).max(7).default(0),
|
||||
});
|
||||
|
||||
export const createEventSchema = z.object({
|
||||
title: z.string().min(1, "Title is required").max(255),
|
||||
description: z.string().min(1, "Description is required"),
|
||||
typeId: z.coerce.number().int().positive(),
|
||||
roomId: z.preprocess(emptyToUndefined, z.coerce.number().int().positive().nullable().optional()),
|
||||
startsAt: z.coerce.date(),
|
||||
endsAt: z.preprocess(emptyToUndefined, z.coerce.date().nullable().optional()),
|
||||
maxPlayers: z.preprocess(emptyToUndefined, z.coerce.number().int().positive().nullable().optional()),
|
||||
isRecurring: z.coerce.number().int().min(0).max(1).default(0),
|
||||
recurrenceRule: z.preprocess(emptyToUndefined, z.string().max(255).nullable().optional()),
|
||||
status: z.enum(["draft", "published", "cancelled", "completed"]).default("draft"),
|
||||
image: z.preprocess(emptyToUndefined, z.string().max(500).nullable().optional()),
|
||||
title: z.string().min(1, "Title is required").max(255),
|
||||
description: z.string().min(1, "Description is required"),
|
||||
typeId: z.coerce.number().int().positive(),
|
||||
roomId: z.preprocess(
|
||||
emptyToUndefined,
|
||||
z.coerce.number().int().positive().nullable().optional(),
|
||||
),
|
||||
startsAt: z.coerce.date(),
|
||||
endsAt: z.preprocess(emptyToUndefined, z.coerce.date().nullable().optional()),
|
||||
maxPlayers: z.preprocess(
|
||||
emptyToUndefined,
|
||||
z.coerce.number().int().positive().nullable().optional(),
|
||||
),
|
||||
isRecurring: z.coerce.number().int().min(0).max(1).default(0),
|
||||
recurrenceRule: z.preprocess(
|
||||
emptyToUndefined,
|
||||
z.string().max(255).nullable().optional(),
|
||||
),
|
||||
status: z
|
||||
.enum(["draft", "published", "cancelled", "completed"])
|
||||
.default("draft"),
|
||||
image: z.preprocess(
|
||||
emptyToUndefined,
|
||||
z.string().max(500).nullable().optional(),
|
||||
),
|
||||
});
|
||||
|
||||
export const updateEventSchema = createEventSchema.partial();
|
||||
|
||||
export const eventPrizeSchema = z.object({
|
||||
eventId: z.coerce.number().int().positive(),
|
||||
position: z.coerce.number().int().positive().default(1),
|
||||
prizeType: z.enum(["badge", "credits", "pixels", "points", "item"]).default("badge"),
|
||||
badgeCode: z.string().max(50).nullable().optional(),
|
||||
credits: z.coerce.number().int().min(0).default(0),
|
||||
pixels: z.coerce.number().int().min(0).default(0),
|
||||
points: z.coerce.number().int().min(0).default(0),
|
||||
itemId: z.coerce.number().int().positive().nullable().optional(),
|
||||
description: z.string().max(255).optional().default(""),
|
||||
eventId: z.coerce.number().int().positive(),
|
||||
position: z.coerce.number().int().positive().default(1),
|
||||
prizeType: z
|
||||
.enum(["badge", "credits", "pixels", "points", "item"])
|
||||
.default("badge"),
|
||||
badgeCode: z.string().max(50).nullable().optional(),
|
||||
credits: z.coerce.number().int().min(0).default(0),
|
||||
pixels: z.coerce.number().int().min(0).default(0),
|
||||
points: z.coerce.number().int().min(0).default(0),
|
||||
itemId: z.coerce.number().int().positive().nullable().optional(),
|
||||
description: z.string().max(255).optional().default(""),
|
||||
});
|
||||
|
||||
export const eventWinnerSchema = z.object({
|
||||
eventId: z.coerce.number().int().positive(),
|
||||
userId: z.coerce.number().int().positive(),
|
||||
position: z.coerce.number().int().positive().default(1),
|
||||
eventId: z.coerce.number().int().positive(),
|
||||
userId: z.coerce.number().int().positive(),
|
||||
position: z.coerce.number().int().positive().default(1),
|
||||
});
|
||||
|
||||
export type EventTypeInput = z.infer<typeof eventTypeSchema>;
|
||||
|
||||
Reference in new issue
Block a user