pos-dashboard/src/services/inventoriesApi.js
2025-08-03 20:55:11 +07:00

61 lines
1.5 KiB
JavaScript

import api from './api';
const ENDPOINTS = {
INVENTORIES: 'inventory',
INVENTORY_BY_ID: (id) => `inventory/${id}`,
};
export const inventoryApi = {
getAllInventories: async (params = {}) => {
try {
const response = await api.get(ENDPOINTS.INVENTORIES, { params });
return response.data;
} catch (error) {
console.error('Error fetching inventories:', error);
throw error;
}
},
getInventoryById: async (id) => {
try {
const response = await api.get(ENDPOINTS.INVENTORY_BY_ID(id));
return response.data;
} catch (error) {
console.error(`Error fetching inventory ${id}:`, error);
throw error;
}
},
createInventory: async (inventoryData) => {
try {
const response = await api.post(ENDPOINTS.INVENTORIES, inventoryData);
return response.data;
} catch (error) {
console.error('Error creating inventory:', error);
throw error;
}
},
updateInventory: async (id, inventoryData) => {
try {
const response = await api.put(ENDPOINTS.INVENTORY_BY_ID(id), inventoryData);
return response.data;
} catch (error) {
console.error(`Error updating inventory ${id}:`, error);
throw error;
}
},
deleteInventory: async (id) => {
try {
const response = await api.delete(ENDPOINTS.INVENTORY_BY_ID(id));
return response.data;
} catch (error) {
console.error(`Error deleting inventory ${id}:`, error);
throw error;
}
},
};
export default inventoryApi;