CEC-4814 - Refactor vehicle_path endpoint (#407)

This commit is contained in:
Paul Adamsen
2023-08-01 13:53:36 -04:00
committed by GitHub
parent 5716832a81
commit c118f676ee
3 changed files with 8 additions and 14 deletions

View File

@@ -112,10 +112,10 @@ export const VehicleProvider = ({ children }) => {
} }
}; };
const getLocationsVehiclePaths = async (token, vinsParam) => { const getLocationsVehiclePaths = async (token, param, vins) => {
try { try {
setBusy(true); setBusy(true);
const result = await api.getLocationsVehiclePaths(token, vinsParam); const result = await api.getLocationsVehiclePaths(token, param, vins);
if (result.error) if (result.error)
throw new Error(`Get locations vehicle paths error. ${result.message}`); throw new Error(`Get locations vehicle paths error. ${result.message}`);
return result; return result;

View File

@@ -44,16 +44,9 @@ const ComponentVehiclePathsMap = (props) => {
const retrieveAndStoreLocations = (accessToken) => { const retrieveAndStoreLocations = (accessToken) => {
let vinsToShowOnMap = [...props.vinsToShowOnMapColors.keys()]; let vinsToShowOnMap = [...props.vinsToShowOnMapColors.keys()];
let vinsParam = "" let param = "lookback_hours=" + props.lookbackHours
for (let vinToShowOnMap of vinsToShowOnMap) {
vinsParam += "vins="
vinsParam += vinToShowOnMap
vinsParam += "&"
}
vinsParam += "lookback_hours="
vinsParam += props.lookbackHours
return getLocationsVehiclePaths(accessToken, vinsParam) return getLocationsVehiclePaths(accessToken, param, vinsToShowOnMap)
.then(async (result) => { .then(async (result) => {
let resultArray = Object.entries(result) let resultArray = Object.entries(result)
const points = [] const points = []

View File

@@ -89,13 +89,14 @@ const vehiclesAPI = {
.then(fetchRespHandler) .then(fetchRespHandler)
.catch(errorHandler), .catch(errorHandler),
getLocationsVehiclePaths: async (token, vinsParam) => getLocationsVehiclePaths: async (token, param, vins) =>
fetch(`${API_ENDPOINT}/vehicle_paths?${vinsParam}`, { fetch(`${API_ENDPOINT}/vehicle_paths?${param}`, {
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: vins }),
}) })
.then(fetchRespHandler) .then(fetchRespHandler)
.catch(errorHandler), .catch(errorHandler),