CEC-4772 - carsconnected takes VINs in req body (#397)

This commit is contained in:
Paul Adamsen
2023-07-24 16:01:39 -04:00
committed by GitHub
parent c572e5de5b
commit d6d1b3107e
4 changed files with 7 additions and 6 deletions

View File

@@ -113,7 +113,7 @@ export const FleetProvider = ({ children }) => {
throw new Error(`Get fleet vehicles error. ${result.message}`); throw new Error(`Get fleet vehicles error. ${result.message}`);
} }
const connectionsResult = await vehiclesAPI.getConnections(result.data, token) const connectionsResult = await vehiclesAPI.getConnections({ "VINs": result.data }, token)
if (result.error) { if (result.error) {
setFleetVehicles([]) setFleetVehicles([])
throw new Error(`Get vehicles connections error. ${result.message}`); throw new Error(`Get vehicles connections error. ${result.message}`);

View File

@@ -35,7 +35,7 @@ export const VehicleProvider = ({ children }) => {
try { try {
if (cars.length === 0) return; if (cars.length === 0) return;
const vins = cars.map((car) => car.vin); const vins = cars.map((car) => car.vin);
const result = await api.getConnections(vins, token); const result = await api.getConnections({ "VINs": vins }, token);
if (result.error) { if (result.error) {
throw new Error(`Add connections error. ${result.message}`); throw new Error(`Add connections error. ${result.message}`);
@@ -80,7 +80,7 @@ export const VehicleProvider = ({ children }) => {
const getConnections = async (vins, token) => { const getConnections = async (vins, token) => {
try { try {
setBusy(true); setBusy(true);
const result = await api.getConnections(vins, token); const result = await api.getConnections({ "VINs": vins }, token);
if (result.error) if (result.error)
throw new Error(`Get connections error. ${result.message}`); throw new Error(`Get connections error. ${result.message}`);
return result; return result;

View File

@@ -116,7 +116,7 @@ const vehiclesAPI = {
getConnections: async (vins) => { getConnections: async (vins) => {
const result = {}; const result = {};
vins.forEach((vin) => { vins.VINs.forEach((vin) => {
result[vin] = true; result[vin] = true;
result["2:" + vin] = false; result["2:" + vin] = false;
}); });

View File

@@ -41,13 +41,14 @@ const vehiclesAPI = {
.catch(errorHandler), .catch(errorHandler),
getConnections: async (vins, token) => { getConnections: async (vins, token) => {
const u = `${API_ENDPOINT}/carsconnected?vins=${vins.join(",")}`; const u = `${API_ENDPOINT}/carsconnected`;
return fetch(u, { return fetch(u, {
method: "GET", method: "POST",
headers: Object.assign( headers: Object.assign(
{ "Content-Type": "application/json" }, { "Content-Type": "application/json" },
getAuthHeaderOptions(token) getAuthHeaderOptions(token)
), ),
body: JSON.stringify(vins),
}) })
.then(fetchRespHandler) .then(fetchRespHandler)
.catch(errorHandler); .catch(errorHandler);