DigitalConsumer.FixMyGlass/src/global-methods.js
2022-03-21 12:05:10 -04:00

68 lines
1.7 KiB
JavaScript

import axios from "axios";
import { applicationConfig } from "@/constants/application-config.js";
import httpStatusCodes from "http-status-codes";
export default {
callHttpClient({ method, endpoint, payload }) {
return new Promise((resolve, reject) => {
// TODO CSR-98 TEMP FOR TESTING
var apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
if (endpoint.includes("order")) {
apiGatewayUrl = "https://localhost:44346";
}
// const apiGatewayUrl = applicationConfig.CONSUMER_APIGATEWAY_URL;
const payloadAndAnalyticsData = Object.assign({}, payload, {
AppName: "FixMyGlass",
});
axios({
method: method,
url: apiGatewayUrl + endpoint,
data: payloadAndAnalyticsData,
crossDomain: true,
responseType: {},
}).then(
(response) => {
if (response.status == httpStatusCodes.OK) {
if(response.data == undefined) {
reject(response);
}else{
resolve(response);
}
} else {
reject(response);
}
},
(error) => {
return reject(error.response);
}
);
});
},
/* istanbul ignore next */
callMockHttpClient({ method, endpoint }) {
// For Mock use only!
return new Promise((resolve, reject) => {
axios({
method: method,
url: endpoint,
crossDomain: true,
responseType: {},
}).then(
(response) => {
if (response.status == httpStatusCodes.OK) {
resolve(response);
} else {
reject(response);
}
},
(error) => {
return reject(error.response);
}
);
});
},
};