From c118f676eef993e3935ad902ae1c5d156af6a9f9 Mon Sep 17 00:00:00 2001 From: Paul Adamsen <117673433+pauladamseniii@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:53:36 -0400 Subject: [PATCH] CEC-4814 - Refactor vehicle_path endpoint (#407) --- src/components/Contexts/VehicleContext.jsx | 4 ++-- src/components/VehiclePathsMap/index.jsx | 11 ++--------- src/services/vehiclesAPI.js | 7 ++++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/components/Contexts/VehicleContext.jsx b/src/components/Contexts/VehicleContext.jsx index ba4458d..909d7c3 100644 --- a/src/components/Contexts/VehicleContext.jsx +++ b/src/components/Contexts/VehicleContext.jsx @@ -112,10 +112,10 @@ export const VehicleProvider = ({ children }) => { } }; - const getLocationsVehiclePaths = async (token, vinsParam) => { + const getLocationsVehiclePaths = async (token, param, vins) => { try { setBusy(true); - const result = await api.getLocationsVehiclePaths(token, vinsParam); + const result = await api.getLocationsVehiclePaths(token, param, vins); if (result.error) throw new Error(`Get locations vehicle paths error. ${result.message}`); return result; diff --git a/src/components/VehiclePathsMap/index.jsx b/src/components/VehiclePathsMap/index.jsx index 10346e6..18929fd 100644 --- a/src/components/VehiclePathsMap/index.jsx +++ b/src/components/VehiclePathsMap/index.jsx @@ -44,16 +44,9 @@ const ComponentVehiclePathsMap = (props) => { const retrieveAndStoreLocations = (accessToken) => { let vinsToShowOnMap = [...props.vinsToShowOnMapColors.keys()]; - let vinsParam = "" - for (let vinToShowOnMap of vinsToShowOnMap) { - vinsParam += "vins=" - vinsParam += vinToShowOnMap - vinsParam += "&" - } - vinsParam += "lookback_hours=" - vinsParam += props.lookbackHours + let param = "lookback_hours=" + props.lookbackHours - return getLocationsVehiclePaths(accessToken, vinsParam) + return getLocationsVehiclePaths(accessToken, param, vinsToShowOnMap) .then(async (result) => { let resultArray = Object.entries(result) const points = [] diff --git a/src/services/vehiclesAPI.js b/src/services/vehiclesAPI.js index 6fe7356..40b3f5a 100644 --- a/src/services/vehiclesAPI.js +++ b/src/services/vehiclesAPI.js @@ -89,13 +89,14 @@ const vehiclesAPI = { .then(fetchRespHandler) .catch(errorHandler), - getLocationsVehiclePaths: async (token, vinsParam) => - fetch(`${API_ENDPOINT}/vehicle_paths?${vinsParam}`, { - method: "GET", + getLocationsVehiclePaths: async (token, param, vins) => + fetch(`${API_ENDPOINT}/vehicle_paths?${param}`, { + method: "POST", headers: Object.assign( { "Content-Type": "application/json" }, getAuthHeaderOptions(token) ), + body: JSON.stringify({ vins: vins }), }) .then(fetchRespHandler) .catch(errorHandler),