almacenar img (sin terminar)

This commit is contained in:
2025-07-21 15:39:27 -04:00
parent c377ab69da
commit a15505ff2c
8 changed files with 153 additions and 50 deletions

View File

@@ -1,13 +1,38 @@
import { user } from '@/feactures/auth/schemas/register';
import { all } from 'axios';
// import { user } from '@/feactures/auth/schemas/register';
// import { all } from 'axios';
import { z } from 'zod';
export type InventoryTable = z.infer<typeof product>;
export type EditInventory = z.infer<typeof editInventory>; //output
export type formDataInput = z.input<typeof editInventory>;
export type EditInventory = z.infer<typeof editInventory>;
export type ProductApiResponseSchema = z.infer<typeof productApiResponseSchema>;
export type allProducts = z.infer<typeof productDetails>;
// --- Esquemas de validación para archivos ---
// Esquema básico para un solo archivo
const fileSchema = z.object({
name: z.string().min(1, 'El nombre del archivo no puede estar vacío.'),
size: z.number().int().positive('El tamaño del archivo debe ser positivo.'),
type: z.string().refine(
(type) => type.startsWith('image/'),
'Solo se permiten archivos de imagen.'
),
// Puedes añadir más validaciones personalizadas aquí
// Por ejemplo, limitar el tamaño máximo a 5MB (5 * 1024 * 1024 bytes)
}).refine(
(file) => file.size <= 5 * 1024 * 1024,
'El tamaño del archivo no debe exceder los 5MB.'
);
// Esquema para un array de archivos (cuando el input es multiple)
const filesArraySchema = z.array(fileSchema).max(5, 'Solo se permiten hasta 5 archivos.');
// const formSchema = z.object({
// file: z
// .instanceof(FileList)
// .refine((file) => file?.length == 1, 'File is required.')
// });
export const product = z.object({
id: z.number().optional(),
title: z.string(),
@@ -16,7 +41,8 @@ export const product = z.object({
// category: z.string(),
stock: z.number(),
price: z.string(),
urlImg: z.string(),
urlImg: z.any(),
// urlImg: z.string(),
status: z.string(),
userId: z.number().optional()
})
@@ -31,12 +57,10 @@ export const editInventory = z.object({
id: z.number().optional(),
title: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }),
description: z.string().min(10, { message: "Debe de tener 10 o más caracteres" }),
stock: z.string().transform(val => Number(val)).pipe(z.number(
{ invalid_type_error: 'El stock debe ser un número' }).min(0, { message: "El stock debe ser mayor a 0" })
),
stock: z.number(),
address: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }),
price: z.string(),
urlImg: z.string(),
urlImg: z.any(),
status: z.string().min(1, { message: "Debe de seleccionar un valor" }),
userId: z.number().optional(),
})