Cambios de nombres de variables y esquema

This commit is contained in:
2025-08-21 15:11:00 -04:00
parent c45307d47d
commit f050db4359
6 changed files with 25 additions and 121 deletions

View File

@@ -118,15 +118,8 @@ export const getProductById = async (id: number) => {
};
export const createProductAction = async (payload: FormData) => {
// const session = await auth()
// const userId = session?.user?.id
// if (userId) {
// payload.append('userId', String(userId));
// }
const [error, data] = await safeFetchApi(
test,
productMutate,
'/products',
'POST',
payload,
@@ -140,19 +133,10 @@ export const createProductAction = async (payload: FormData) => {
return data;
};
export const updateUserAction2 = async (payload: InventoryTable) => {
try {
// const { id, urlImg, ...payloadWithoutId } = payload;
// const formData = new FormData();
// formData.append('file', urlImg);
// console.log(formData);
export const updateProductAction = async (payload: InventoryTable) => {
try {
const [error, data] = await safeFetchApi(
test,
productMutate,
`/products/upload`,
'PATCH',
payload,
@@ -170,27 +154,6 @@ export const updateUserAction2 = async (payload: InventoryTable) => {
}
}
export const updateUserAction = async (payload: InventoryTable) => {
try {
const { id, ...payloadWithoutId } = payload;
const [error, data] = await safeFetchApi(
productMutate,
`/products/${id}`,
'PATCH',
payloadWithoutId,
);
if (error) {
console.error(error);
throw new Error(error?.message || 'Error al actualizar el producto');
}
return data;
} catch (error) {
console.error(error);
}
}
export const deleteProductAction = async (id: Number) => {
const [error] = await safeFetchApi(
productMutate,

View File

@@ -1,6 +1,6 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { EditInventory } from "../schemas/inventory";
import { updateUserAction, createProductAction, updateUserAction2 } from "../actions/actions";
// import { EditInventory } from "../schemas/inventory";
import { updateProductAction, createProductAction, } from "../actions/actions";
// Create mutation
export function useCreateProduct() {
@@ -17,7 +17,7 @@ export function useUpdateProduct() {
const queryClient = useQueryClient();
const mutation = useMutation({
// mutationFn: (data: EditInventory) => updateUserAction(data),
mutationFn: (data: any) => updateUserAction2(data),
mutationFn: (data: any) => updateProductAction(data),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ['product'] }),
onError: (e) => console.error('Error:', e)
})

View File

@@ -3,7 +3,7 @@
import { url } from 'inspector';
import { z } from 'zod';
export type InventoryTable = z.infer<typeof product>;
export type InventoryTable = z.infer<typeof seeProduct>;
export type EditInventory = z.infer<typeof editInventory>;
export type ProductApiResponseSchema = z.infer<typeof productApiResponseSchema>;
export type allProducts = z.infer<typeof productDetails>;
@@ -17,12 +17,10 @@ export const product = z.object({
title: z.string(),
description: z.string(),
address: z.string(),
// category: z.string(),
stock: z.number(),
price: z.string(),
urlImg: z.custom<FileList | undefined>().optional(),
gallery: z.array(z.string()).optional(),
// urlImg: z.string(),
status: z.string(),
userId: z.number().optional()
})
@@ -98,7 +96,7 @@ export const test = z.object({
export const productMutate = z.object({
message: z.string(),
data: product,
data: seeProduct,
})
export const getProduct = z.object({