* add deploy button * disable control if inactive * add cases (cherry picked from commit 91b2a8c8aab546221db8da8eaed22bca78c4d91f) Co-authored-by: Tristan Timblin <ttimblin@fiskerinc.com>
128 lines
3.4 KiB
JavaScript
128 lines
3.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);
|
|
},
|
|
|
|
deployCarUpdate: async (id, token) => {
|
|
return fetch(`${API_ENDPOINT}/carupdate/${id}/deploy`, {
|
|
method: "POST",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler);
|
|
},
|
|
|
|
getSUMSVersions: async (token) => {
|
|
return fetch(`${API_ENDPOINT}/manifest/sums`, {
|
|
method: "GET",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token)
|
|
),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler);
|
|
},
|
|
|
|
updateSUMSVersion: async (id, version, token) => {
|
|
return fetch(`${API_ENDPOINT}/manifests/${id}/sums`, {
|
|
method: "PUT",
|
|
headers: Object.assign(
|
|
{ "Content-Type": "application/json" },
|
|
getAuthHeaderOptions(token),
|
|
),
|
|
body: JSON.stringify({ version }),
|
|
})
|
|
.then(fetchRespHandler)
|
|
.catch(errorHandler);
|
|
}
|
|
};
|
|
|
|
export default updatesAPI; |