CEC-1965 Supplier update and approval (#162)

* CEC-1965 Supplier update and approval
Fix calling connectedcars for no VINs
Search sets table page to 0

* PR comments
This commit is contained in:
John Wu
2022-07-01 12:39:21 -07:00
committed by GitHub
parent d9cbf9ef23
commit fe40c26c56
23 changed files with 1883 additions and 82 deletions

View File

@@ -0,0 +1,61 @@
const data = [
{
email: "test@supplier.com",
address: "address",
company: "company",
contact: "contact",
created: "2021-07-14T20:09:40.98187Z",
ecus: ["ADAS"],
program: "Ocean",
telephone: "555-555-5555",
updated: "2021-07-15T21:09:40.98187Z",
},
{
email: "test2@supplier.com",
address: "address",
company: "company",
contact: "contact",
created: "2021-07-16T22:09:40.98187Z",
ecus: ["ICC", "BCM"],
program: "Pear",
telephone: "555-555-5555",
updated: "2021-07-17T20:09:40.98187Z",
},
{
email: "test3@supplier.com",
address: "address",
company: "company",
contact: "contact",
created: "2021-07-16T22:09:40.98187Z",
ecus: ["BCM"],
program: "Ocean",
telephone: "555-555-5555",
updated: "2021-07-17T20:09:40.98187Z",
},
];
const suppliersAPI = {
addSupplier: async (supplier) => {
data.push(supplier);
return supplier;
},
deleteSupplier: async (email) => {
const index = data.findIndex((element) => element.email === email);
if (index >= 0) data.splice(index, 1);
return email;
},
getSupplier: async (email) => {
const index = data.findIndex((element) => element.email === email);
return data[index];
},
getSuppliers: async () => {
return { data };
},
updateSupplier: async (email, supplier) => {
const index = data.findIndex((element) => element.email === email);
if (index >= 0) data[index] = supplier;
return supplier;
},
};
export default suppliersAPI;

View File

@@ -0,0 +1,72 @@
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),
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;