106 lines
3.9 KiB
JavaScript
106 lines
3.9 KiB
JavaScript
import axios from 'axios';
|
|
|
|
const getAuthHeader = () => {
|
|
const bmToken =
|
|
(typeof document !== 'undefined'
|
|
? document.cookie
|
|
.split('; ')
|
|
.find((row) => row.startsWith('bm-token='))
|
|
?.split('=')[1]
|
|
: null) || (typeof localStorage !== 'undefined' ? localStorage.getItem('bm-token') : null);
|
|
return bmToken && bmToken !== 'undefined' && bmToken !== 'null' ? { Authorization: `Bearer ${bmToken}` } : {};
|
|
};
|
|
|
|
export const WarehouseItemService = {
|
|
// ─── Items ────────────────────────────────────────────────────────────────
|
|
listItems: async (params = {}) => {
|
|
const response = await axios.get('/api/warehouse-items/admin/items', {
|
|
params,
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
createItem: async (data) => {
|
|
const response = await axios.post('/api/warehouse-items/admin/items', data, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
getItem: async (itemId) => {
|
|
const response = await axios.get(`/api/warehouse-items/admin/items/${itemId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
updateItem: async (itemId, data) => {
|
|
const response = await axios.patch(`/api/warehouse-items/admin/items/${itemId}`, data, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
deleteItem: async (itemId) => {
|
|
await axios.delete(`/api/warehouse-items/admin/items/${itemId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
},
|
|
|
|
// ─── Transactions ─────────────────────────────────────────────────────────
|
|
listTransactions: async (params = {}) => {
|
|
const response = await axios.get('/api/warehouse-items/admin/transactions', {
|
|
params,
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
createTransaction: async (data) => {
|
|
const response = await axios.post('/api/warehouse-items/admin/transactions', data, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
deleteTransaction: async (transactionId) => {
|
|
await axios.delete(`/api/warehouse-items/admin/transactions/${transactionId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
},
|
|
|
|
// ─── Stock ────────────────────────────────────────────────────────────────
|
|
getTotalStock: async () => {
|
|
const response = await axios.get('/api/warehouse-items/admin/stock/total', {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
getStockByItem: async (itemId) => {
|
|
const response = await axios.get(`/api/warehouse-items/admin/stock/by-item/${itemId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
getStockByWarehouse: async (warehouseId) => {
|
|
const response = await axios.get(`/api/warehouse-items/admin/stock/by-warehouse/${warehouseId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
}
|
|
};
|