69 lines
2.1 KiB
TypeScript
69 lines
2.1 KiB
TypeScript
import { title } from 'process';
|
|
import { z } from 'zod';
|
|
|
|
export type InventoryTable = z.infer<typeof product>;
|
|
export type CreateUser = z.infer<typeof createUser>;
|
|
export type UpdateUser = z.infer<typeof updateUser>;
|
|
|
|
export const product = z.object({
|
|
id: z.number().optional(),
|
|
title: z.string(),
|
|
description: z.string(),
|
|
// price: z.number(),
|
|
// quantity: z.number(),
|
|
// category: z.string(),
|
|
// image: z.string().optional(),
|
|
stock: z.number(),
|
|
price: z.string(),
|
|
urlImg: z.string(),
|
|
userId: z.number().optional(),
|
|
});
|
|
|
|
export const createUser = z.object({
|
|
id: z.number().optional(),
|
|
username: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }),
|
|
password: z.string().min(8, { message: "Debe de tener 8 o más caracteres" }),
|
|
email: z.string().email({ message: "Correo no válido" }),
|
|
fullname: z.string(),
|
|
phone: z.string(),
|
|
confirmPassword: z.string(),
|
|
role: z.number()
|
|
})
|
|
.refine((data) => data.password === data.confirmPassword, {
|
|
message: 'La contraseña no coincide',
|
|
path: ['confirmPassword'],
|
|
})
|
|
|
|
export const updateUser = z.object({
|
|
id: z.number(),
|
|
username: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }).or(z.literal('')),
|
|
password: z.string().min(6, { message: "Debe de tener 6 o más caracteres" }).or(z.literal('')),
|
|
email: z.string().email({ message: "Correo no válido" }).or(z.literal('')),
|
|
fullname: z.string().optional(),
|
|
phone: z.string().optional(),
|
|
role: z.number().optional(),
|
|
isActive: z.boolean().optional(),
|
|
state: z.number().optional().nullable(),
|
|
municipality: z.number().optional().nullable(),
|
|
parish: z.number().optional().nullable(),
|
|
})
|
|
|
|
export const surveysApiResponseSchema = z.object({
|
|
message: z.string(),
|
|
data: z.array(product),
|
|
meta: z.object({
|
|
page: z.number(),
|
|
limit: z.number(),
|
|
totalCount: z.number(),
|
|
totalPages: z.number(),
|
|
hasNextPage: z.boolean(),
|
|
hasPreviousPage: z.boolean(),
|
|
nextPage: z.number().nullable(),
|
|
previousPage: z.number().nullable(),
|
|
}),
|
|
})
|
|
|
|
export const productMutate = z.object({
|
|
message: z.string(),
|
|
data: product,
|
|
}) |