Fortellis cleanup.
This commit is contained in:
@@ -26,11 +26,8 @@ class FortellisApiError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
axiosCurlirize(axios, (result, err) => {
|
||||
// if (err) {
|
||||
// use your logger here
|
||||
// } else {
|
||||
// }
|
||||
axiosCurlirize(axios, (_result, _err) => {
|
||||
//Left intentionally blank. We don't want to console.log. We handle logging the cURL in MakeFortellisCall once completed.
|
||||
});
|
||||
|
||||
const getTransactionType = (jobid) => `fortellis:${jobid}`;
|
||||
@@ -84,7 +81,7 @@ async function FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObj
|
||||
return SubscriptionMetaFromCache;
|
||||
} else {
|
||||
const access_token = await GetAuthToken();
|
||||
const subscriptions = await axios.get(`https://subscriptions.fortellis.io/v1/solution/subscriptions`, {
|
||||
const subscriptions = await axios.get(FortellisActions.GetSubscription.url, {
|
||||
headers: { Authorization: `Bearer ${access_token}` },
|
||||
logRequest: false
|
||||
});
|
||||
@@ -116,15 +113,15 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta, overr
|
||||
console.log(JSON.stringify(SubscriptionMeta.apiDmsInfo, null, 4));
|
||||
console.log("===========");
|
||||
}
|
||||
//TODO: Verify how to select the correct department.
|
||||
const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object.
|
||||
|
||||
const departmentIds = SubscriptionMeta.apiDmsInfo //Get the subscription object.
|
||||
.find((info) => info.name === apiName)?.departments; //Departments are categorized by API name and have an array of departments.
|
||||
|
||||
if (overrideDepartmentId) {
|
||||
return departmentIds2 && departmentIds2.find(d => d.id === overrideDepartmentId)?.id //TODO: This makes the assumption that there is only 1 department.
|
||||
return departmentIds && departmentIds.find(d => d.id === overrideDepartmentId)?.id
|
||||
} else {
|
||||
|
||||
return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department.
|
||||
return departmentIds && departmentIds[0] && departmentIds[0].id; //TODO: This makes the assumption that there is only 1 department.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,11 +141,10 @@ async function MakeFortellisCall({
|
||||
SubscriptionObject, //This is used because of the get make models to bypass all of the redis calls.
|
||||
overrideDepartmentId
|
||||
}) {
|
||||
const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
||||
//const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
||||
|
||||
const fullUrl = constructFullUrl({ url, pathParams: requestPathParams, requestSearchParams });
|
||||
|
||||
if (debug) logger.log(`Executing ${type} to ${fullUrl}`);
|
||||
if (debug) console.log(`Executing ${type} to ${fullUrl}`);
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject });
|
||||
@@ -207,7 +203,7 @@ async function MakeFortellisCall({
|
||||
|
||||
if (debug) {
|
||||
console.log(`ReqID: ${ReqId} Data`);
|
||||
//console.log(JSON.stringify(result.data, null, 4));
|
||||
console.log(JSON.stringify(result.data, null, 4));
|
||||
}
|
||||
|
||||
if (result.data.checkStatusAfterSeconds) {
|
||||
@@ -236,9 +232,6 @@ async function MakeFortellisCall({
|
||||
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
console.log(`ReqID: ${ReqId} Error`, error.response?.data);
|
||||
//console.log(`ReqID: ${ReqId} Full Error`, JSON.stringify(error, null, 4));
|
||||
|
||||
const errorDetails = {
|
||||
reqId: ReqId,
|
||||
url: fullUrl,
|
||||
@@ -263,12 +256,6 @@ async function MakeFortellisCall({
|
||||
true
|
||||
);
|
||||
|
||||
// CreateFortellisLogEvent(socket, "ERROR", `Error in MakeFortellisCall for ${apiName}: ${error.message}`, {
|
||||
// ...errorDetails,
|
||||
// errorStack: error.stack
|
||||
// });
|
||||
|
||||
// Throw custom error with all the details
|
||||
throw new FortellisApiError(`Fortellis API call failed for ${apiName}: ${error.message}`, errorDetails);
|
||||
}
|
||||
}
|
||||
@@ -312,7 +299,15 @@ function sleep(ms) {
|
||||
|
||||
const isProduction = process.env.NODE_ENV === "production";
|
||||
|
||||
//Get requests should have the trailing slash as they are used that way in the calls.
|
||||
const FortellisActions = {
|
||||
GetSubscription: {
|
||||
url: isProduction
|
||||
? "https://subscriptions.fortellis.io/v1/solution/subscriptions"
|
||||
: "https://subscriptions.fortellis.io/v1/solution/subscriptions",
|
||||
type: "get",
|
||||
apiName: "Fortellis Get Subscriptions"
|
||||
},
|
||||
QueryVehicles: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdkdrive/service/v1/vehicles/"
|
||||
@@ -412,7 +407,7 @@ const FortellisActions = {
|
||||
},
|
||||
QueryErrorWip: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/errWIP/" //Get requests should have the trailing slash/
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/errWIP/"
|
||||
: "https://api.fortellis.io/cdk-test/drive/glpost/errWIP/",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Accounts GL"
|
||||
|
||||
Reference in New Issue
Block a user