sync
This commit is contained in:
40
validation/matches.js
Normal file
40
validation/matches.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const MATCH_STATUS = {
|
||||
SCHEDULED: 'scheduled',
|
||||
LIVE: 'live',
|
||||
FINISHED: 'finished',
|
||||
};
|
||||
|
||||
export const listMatchesQuerySchema = z.object({
|
||||
limit: z.coerce.number().int().positive().max(100).optional(),
|
||||
});
|
||||
|
||||
export const matchIdParamSchema = z.object({
|
||||
id: z.coerce.number().int().positive(),
|
||||
});
|
||||
|
||||
export const createMatchSchema = z.object({
|
||||
sport: z.string().min(1),
|
||||
homeTeam: z.string().min(1),
|
||||
awayTeam: z.string().min(1),
|
||||
startTime: z.iso.datetime(),
|
||||
endTime: z.iso.datetime(),
|
||||
homeScore: z.coerce.number().int().nonnegative().optional(),
|
||||
awayScore: z.coerce.number().int().nonnegative().optional(),
|
||||
}).superRefine((data, ctx) => {
|
||||
const start = new Date(data.startTime);
|
||||
const end = new Date(data.endTime);
|
||||
if (end <= start) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "endTime must be chronologically after startTime",
|
||||
path: ["endTime"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const updateScoreSchema = z.object({
|
||||
homeScore: z.coerce.number().int().nonnegative(),
|
||||
awayScore: z.coerce.number().int().nonnegative(),
|
||||
});
|
||||
Reference in New Issue
Block a user