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"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const CreateFortellisLogEvent = (socket, level, message, txnDetails) => {
|
||||
//TODO: Add detaisl to track the whole transaction between Fortellis and the server.
|
||||
logger.log("fortellis-log-event", level, socket?.user?.email, null, { wsmessage: message, txnDetails });
|
||||
socket.emit("fortellis-log-event", { level, message, txnDetails });
|
||||
};
|
||||
|
||||
@@ -75,7 +75,6 @@ async function FortellisJobExport({ socket, redisHelpers, txEnvelope, jobid }) {
|
||||
defaultFortellisTTL
|
||||
);
|
||||
|
||||
//TODO: Need to remove unnecessary stuff here to reduce the payload.
|
||||
const JobData = await QueryJobData({ socket, jobid });
|
||||
|
||||
await setSessionTransactionData(
|
||||
@@ -356,7 +355,7 @@ async function CalculateDmsVid({ socket, JobData, redisHelpers }) {
|
||||
vin: JobData.v_vin,
|
||||
jobId: JobData.id
|
||||
});
|
||||
throw error; // Re-throw to maintain existing error handling flow
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -410,9 +409,6 @@ async function QueryDmsCustomerByName({ socket, redisHelpers, JobData }) {
|
||||
["firstName", JobData.ownr_fn.replace(replaceSpecialRegex, "")],
|
||||
["lastName", JobData.ownr_ln.replace(replaceSpecialRegex, "")]
|
||||
];
|
||||
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `Begin query DMS Customer by Name using ${JSON.stringify(ownerName)} `);
|
||||
|
||||
try {
|
||||
const result = await MakeFortellisCall({
|
||||
...FortellisActions.QueryCustomerByName,
|
||||
@@ -903,7 +899,7 @@ async function UpdateDmsVehicle({ socket, redisHelpers, JobData, DMSVeh, DMSCust
|
||||
...DMSVehToSend,
|
||||
dealer: {
|
||||
...DMSVehToSend.dealer, //TODO: Check why company is blank on a queried record.
|
||||
//company: "77",
|
||||
|
||||
...((txEnvelope.inservicedate || DMSVehToSend.dealer.inServiceDate) && {
|
||||
inServiceDate:
|
||||
txEnvelope.dms_unsold === true
|
||||
@@ -1014,8 +1010,8 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
|
||||
srcCo: JobData.bodyshop.cdk_configuration.srcco,
|
||||
srcJrnl: txEnvelope.journal,
|
||||
transID: "",
|
||||
userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid,
|
||||
userName: "PROGRAM, PARTNER"
|
||||
userID: JobData.bodyshop.cdk_configuration.cashierid,
|
||||
userName: "IMEX"
|
||||
|
||||
// acctgDate: "2025-07-07",
|
||||
// desc: "DOCUMENT DESC. OPTIONAL REQUIREMENT",
|
||||
@@ -1043,26 +1039,6 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function InsertDmsBatchWip({ socket, redisHelpers, JobData }) {
|
||||
try {
|
||||
const result = await MakeFortellisCall({
|
||||
...FortellisActions.TranBatchWip,
|
||||
headers: {},
|
||||
redisHelpers,
|
||||
socket,
|
||||
jobid: JobData.id,
|
||||
body: await GenerateTransWips({ socket, redisHelpers, JobData })
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
handleFortellisApiError(socket, error, "InsertDmsBatchWip", {
|
||||
jobId: JobData.id,
|
||||
errorStack: error.stack
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function GenerateTransWips({ socket, redisHelpers, JobData }) {
|
||||
//3rd prop sets fortellis to true to maintain logging.
|
||||
const allocations = await CalculateAllocations(socket, JobData.id, true);
|
||||
|
||||
Reference in New Issue
Block a user