55 lines
1.8 KiB
JavaScript
55 lines
1.8 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 WarehouseService = {
|
|
listWarehouses: async (params = {}) => {
|
|
const response = await axios.get('/api/warehouses/admin/get-all', {
|
|
params,
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
createWarehouse: async (data) => {
|
|
const response = await axios.post('/api/warehouses/admin/create', data, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
getWarehouse: async (warehouseId) => {
|
|
const response = await axios.get(`/api/warehouses/admin/get-one/${warehouseId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
updateWarehouse: async (warehouseId, data) => {
|
|
const response = await axios.patch(`/api/warehouses/admin/update/${warehouseId}`, data, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
return response.data.data;
|
|
},
|
|
|
|
deleteWarehouse: async (warehouseId) => {
|
|
await axios.delete(`/api/warehouses/admin/delete/${warehouseId}`, {
|
|
withCredentials: true,
|
|
headers: getAuthHeader()
|
|
});
|
|
}
|
|
};
|