84 lines
2.1 KiB
JavaScript
84 lines
2.1 KiB
JavaScript
import {
|
|
errorHandler,
|
|
getAuthHeaderOptions,
|
|
fetchRespHandler,
|
|
addQueryParams,
|
|
} from "../utils/http";
|
|
|
|
const API_ENDPOINT = process.env.REACT_APP_UPLOAD_SERVICE_URL;
|
|
|
|
const suppliersAPI = {
|
|
addSupplier: async (vehicle, token) =>
|
|
fetch(`${API_ENDPOINT}/supplier`, {
|
|
method: "POST",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
body: JSON.stringify(vehicle),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler),
|
|
|
|
activateSupplier: async (email, token) =>
|
|
fetch(`${API_ENDPOINT}/supplier/activate/${email}`, {
|
|
method: "POST",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler),
|
|
|
|
deleteSupplier: async (email, token) =>
|
|
fetch(`${API_ENDPOINT}/supplier/${email}`, {
|
|
method: "DELETE",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler),
|
|
|
|
getSupplier: async (email, token, signal) =>
|
|
fetch(`${API_ENDPOINT}/supplier/${email}`, {
|
|
method: "GET",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
signal,
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler),
|
|
|
|
getSuppliers: async (search, token) => {
|
|
const u = addQueryParams(`${API_ENDPOINT}/suppliers`, search);
|
|
return fetch(u, {
|
|
method: "GET",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler);
|
|
},
|
|
|
|
updateSupplier: async (email, supplier, token) =>
|
|
fetch(`${API_ENDPOINT}/supplier/${email}`, {
|
|
method: "PUT",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
body: JSON.stringify(supplier),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler),
|
|
};
|
|
|
|
export default suppliersAPI;
|