37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
export const sportSchema = z.object({
|
|
id: z.uuid(),
|
|
name: z.string(),
|
|
slug: z.string(),
|
|
isActive: z.boolean(),
|
|
createdAt: z.string().datetime(),
|
|
updatedAt: z.string().datetime(),
|
|
})
|
|
|
|
export const createSportSchema = z.object({
|
|
name: z
|
|
.string()
|
|
.trim()
|
|
.min(2, 'El deporte debe tener al menos 2 caracteres.')
|
|
.max(80, 'El deporte no puede superar los 80 caracteres.'),
|
|
})
|
|
|
|
export const updateSportSchema = z
|
|
.object({
|
|
name: z
|
|
.string()
|
|
.trim()
|
|
.min(2, 'El deporte debe tener al menos 2 caracteres.')
|
|
.max(80, 'El deporte no puede superar los 80 caracteres.')
|
|
.optional(),
|
|
isActive: z.boolean().optional(),
|
|
})
|
|
.refine((payload) => payload.name !== undefined || payload.isActive !== undefined, {
|
|
message: 'Debes enviar al menos un campo para actualizar.',
|
|
})
|
|
|
|
export type Sport = z.infer<typeof sportSchema>
|
|
export type CreateSportInput = z.infer<typeof createSportSchema>
|
|
export type UpdateSportInput = z.infer<typeof updateSportSchema>
|