Last active
July 13, 2024 22:38
-
-
Save codigoconjuan/291951706e70b8ae43553b8be6bec9ba to your computer and use it in GitHub Desktop.
Schema de Validación de ZOD para Productos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const ProductSchema = z.object({ | |
name: z.string() | |
.trim() | |
.min(1, { message: 'El Nombre del Producto no puede ir vacio'}), | |
price: z.string() | |
.trim() | |
.transform((value) => parseFloat(value)) | |
.refine((value) => value > 0, { message: 'Precio no válido' }) | |
.or(z.number().min(1, {message: 'La Categoría es Obligatoria' })), | |
categoryId: z.string() | |
.trim() | |
.transform((value) => parseInt(value)) | |
.refine((value) => value > 0, { message: 'La Categoría es Obligatoria' }) | |
.or(z.number().min(1, {message: 'La Categoría es Obligatoria' })), | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gracias