Files
ota-admin-portal/src/services/updatesAPI.js
John Wu 2ec340efc5 CEC-3301, CEC-3317 Magna security dll and remote commands (#249)
* CEC-3301, CEC-3317 Magna security dll and remote commands

* Fix test
2022-12-12 10:59:30 -08:00

92 lines
2.4 KiB
JavaScript

import {
addQueryParams, errorHandler, fetchRespHandler, getAuthHeaderOptions
} from "../utils/http";
const API_ENDPOINT = process.env.REACT_APP_OTA_SERVICE_URL;
const createDeployUpdatesClosure = (suffix) => {
return async (data, token) =>
fetch(`${API_ENDPOINT}/${suffix}`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
body: JSON.stringify(data),
})
.then(fetchRespHandler)
.catch(errorHandler);
};
const updatesAPI = {
createFleetUpdates: createDeployUpdatesClosure("fleetupdate"),
createCarUpdates: createDeployUpdatesClosure("carupdate"),
getCarUpdateLog: async (query, token) => {
const u = addQueryParams(`${API_ENDPOINT}/carupdateslog`, query);
return fetch(u, {
method: "GET",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
getCarUpdateProgress: async (carupdateids, token) => {
const u = `${API_ENDPOINT}/carupdatesstatuses?carupdateids=${carupdateids}`;
return fetch(u, {
method: "GET",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
getCarUpdates: async (search, token) => {
const u = addQueryParams(`${API_ENDPOINT}/carupdates`, search);
return fetch(u, {
method: "GET",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
getVINUpdates: async (vin, token) => {
const u = addQueryParams(`${API_ENDPOINT}/carupdates`, { vin });
return fetch(u, {
method: "GET",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
cancelCarUpdate: async (id, token) => {
return fetch(`${API_ENDPOINT}/carupdate/${id}/cancel`, {
method: "POST",
headers: Object.assign(
{ "Content-Type": "application/json" },
getAuthHeaderOptions(token)
),
})
.then(fetchRespHandler)
.catch(errorHandler);
},
};
export default updatesAPI;