editar, modificar, ver y crear productos listo
This commit is contained in:
@@ -4,14 +4,11 @@ import {
|
||||
ApiResponseSchema,
|
||||
InventoryTable,
|
||||
productMutate,
|
||||
test,
|
||||
// editInventory,
|
||||
productApiResponseSchema,
|
||||
getProduct
|
||||
getProduct,
|
||||
deleteProduct
|
||||
} from '../schemas/inventory';
|
||||
|
||||
import { auth } from '@/lib/auth';
|
||||
|
||||
export const getInventoryAction = async (params: {
|
||||
page?: number;
|
||||
limit?: number;
|
||||
@@ -53,7 +50,7 @@ export const getInventoryAction = async (params: {
|
||||
nextPage: null,
|
||||
previousPage: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export const getAllProducts = async (params: {
|
||||
@@ -100,9 +97,12 @@ export const getAllProducts = async (params: {
|
||||
previousPage: null,
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const getProductById = async (id: number) => {
|
||||
if (!id) {
|
||||
return null;
|
||||
}
|
||||
const [error, data] = await safeFetchApi(
|
||||
getProduct,
|
||||
`/products/id/${id}`,
|
||||
@@ -110,12 +110,15 @@ export const getProductById = async (id: number) => {
|
||||
);
|
||||
|
||||
if (error) {
|
||||
if (error.details.status === 404){
|
||||
return null
|
||||
}
|
||||
console.error('❌ Error en la API:', error);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
}
|
||||
|
||||
export const createProductAction = async (payload: FormData) => {
|
||||
const [error, data] = await safeFetchApi(
|
||||
@@ -131,7 +134,7 @@ export const createProductAction = async (payload: FormData) => {
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
}
|
||||
|
||||
export const updateProductAction = async (payload: InventoryTable) => {
|
||||
try {
|
||||
@@ -155,13 +158,16 @@ export const updateProductAction = async (payload: InventoryTable) => {
|
||||
}
|
||||
|
||||
export const deleteProductAction = async (id: Number) => {
|
||||
if (!id) {
|
||||
throw new Error('Error al eliminar el producto')
|
||||
}
|
||||
const [error] = await safeFetchApi(
|
||||
productMutate,
|
||||
deleteProduct,
|
||||
`/products/${id}`,
|
||||
'DELETE'
|
||||
)
|
||||
console.log(error);
|
||||
if (error) throw new Error(error.message || 'Error al eliminar el usuario')
|
||||
if (error) throw new Error(error.message || 'Error al eliminar el producto')
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user