Update to use proper API call.

This commit is contained in:
Chloe Herd 2023-03-14 12:18:15 -04:00
parent 5ef2c75016
commit 4553fa699d
3 changed files with 11 additions and 22 deletions

View file

@ -55,7 +55,7 @@ const endpoints = {
method: "POST", method: "POST",
}, },
LookupVinByImage: { LookupVinByImage: {
url: "https://localhost:44331/vehicle/api/v1/vehicle/vins-by-image", url: "/vehicle/api/v1/vehicle/vins-by-image",
method: "POST", method: "POST",
}, },
IsVinByAddressPermissible: { IsVinByAddressPermissible: {

View file

@ -7,10 +7,16 @@ import { GaCategories, GaActions, GaLabels } from "@/constants/analytics";
import { headerKeys } from "@/constants/header-keys"; import { headerKeys } from "@/constants/header-keys";
export default { export default {
callHttpClient({ method, endpoint, payload, logApiCall = true }) { callHttpClient({ method, endpoint, payload, logApiCall = true, isFormData = false }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO; const cfDistroUrl = applicationConfig.CONSUMER_CF_DISTRO;
const payloadAndAnalyticsData = Object.assign({}, payload, { AppName: "FixMyGlass" }); let payloadAndAnalyticsData = {};
if (isFormData) {
payloadAndAnalyticsData = payload;
payloadAndAnalyticsData.append("AppName", "FixMyGlass");
} else {
Object.assign(payloadAndAnalyticsData, payload, { AppName: "FixMyGlass" });
}
const headers = { const headers = {
[headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings), [headerKeys.EXPERIMENT]: JSON.stringify(store.getters.experimentSettings),
}; };
@ -53,24 +59,6 @@ export default {
}); });
}, },
// TODO: Remove after replacing test endpoint with real endpoint, then call through normal api call.
callExternalHttpClient({ method, endpoint, payload }) {
return new Promise((resolve, reject) => {
axios({
method: method,
url: endpoint,
data: payload,
}).then(
(response) => {
return resolve(response);
},
(error) => {
return reject(error.response);
}
);
});
},
/* istanbul ignore next */ /* istanbul ignore next */
callMockHttpClient({ method, endpoint }) { callMockHttpClient({ method, endpoint }) {
// For Mock use only! // For Mock use only!

View file

@ -533,10 +533,11 @@ export const actions = {
lookupVinByImage(context, image) { lookupVinByImage(context, image) {
const data = new FormData(); const data = new FormData();
data.append("vinImage", image); data.append("vinImage", image);
return globalMethods.callExternalHttpClient({ return globalMethods.callHttpClient({
method: endpoints.LookupVinByImage.method, method: endpoints.LookupVinByImage.method,
endpoint: endpoints.LookupVinByImage.url, endpoint: endpoints.LookupVinByImage.url,
payload: data, payload: data,
isFormData: true,
}); });
}, },
isVinByAddressPermissible(context, zip) { isVinByAddressPermissible(context, zip) {