Fortellis cleanup.
This commit is contained in:
47252
VendorsBulk.json
47252
VendorsBulk.json
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
||||
Fortellis Feedback
|
||||
|
||||
Create Customer
|
||||
https://apidocs.fortellis.io/apis/c5cfb5b3-2013-4870-8645-0379c01ae56b
|
||||
Request Body compoennts do not show on website. Unable to determine which components are required.
|
||||
@@ -69,7 +69,6 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
};
|
||||
|
||||
const handleFinish = (values) => {
|
||||
//TODO: Add this as a split instead.
|
||||
if (Fortellis.treatment === "on") {
|
||||
wsssocket.emit("fortellis-export-job", {
|
||||
jobid: job.id,
|
||||
@@ -84,9 +83,8 @@ export function DmsPostForm({ bodyshop, socket, job, logsRef }) {
|
||||
txEnvelope: values
|
||||
});
|
||||
}
|
||||
console.log(logsRef);
|
||||
|
||||
if (logsRef) {
|
||||
console.log("executing", logsRef);
|
||||
logsRef.curent &&
|
||||
logsRef.current.scrollIntoView({
|
||||
behavior: "smooth"
|
||||
|
||||
@@ -14,12 +14,10 @@ const { DiscountNotAlreadyCounted } = InstanceManager({
|
||||
|
||||
exports.defaultRoute = async function (req, res) {
|
||||
try {
|
||||
//Fortellis TODO: determine when this is called and whether refactor is required.
|
||||
WsLogger.createLogEvent(req, "DEBUG", `Received request to calculate allocations for ${req.body.jobid}`);
|
||||
const jobData = await QueryJobData(req, req.BearerToken, req.body.jobid);
|
||||
return res.status(200).json({ data: calculateAllocations(req, jobData) });
|
||||
} catch (error) {
|
||||
////console.log(error);
|
||||
WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
|
||||
WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`);
|
||||
res.status(500).json({ error: `Error encountered in CdkCalculateAllocations. ${error}` });
|
||||
@@ -31,7 +29,6 @@ exports.default = async function (socket, jobid, isFortellis = false) {
|
||||
const jobData = await QueryJobData(socket, "Bearer " + socket.handshake.auth.token, jobid, isFortellis);
|
||||
return calculateAllocations(socket, jobData, isFortellis);
|
||||
} catch (error) {
|
||||
////console.log(error);
|
||||
const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent;
|
||||
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
|
||||
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`);
|
||||
|
||||
@@ -178,14 +178,14 @@ exports.fortellis = async function ReloadFortellisMakes(req, res) {
|
||||
})
|
||||
});
|
||||
|
||||
logger.log("cdk-replace-makes-models-success", "DEBUG", req.user.email, null, {
|
||||
logger.log("fortellis-replace-makes-models-success", "DEBUG", req.user.email, null, {
|
||||
cdk_dealerid,
|
||||
count: newList.length
|
||||
});
|
||||
|
||||
res.sendStatus(200);
|
||||
} catch (error) {
|
||||
logger.log("cdk-replace-makes-models-error", "ERROR", req.user.email, null, {
|
||||
logger.log("fortellis-replace-makes-models-error", "ERROR", req.user.email, null, {
|
||||
cdk_dealerid,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -262,7 +262,7 @@ const redisSocketEvents = ({
|
||||
});
|
||||
} catch (error) {
|
||||
FortellisLogger(socket, "error", `Error during Fortellis export : ${error.message}`);
|
||||
logger.log("fortellis-job-export-error", "error", null, null, {
|
||||
logger.log("fortellis-job-export-error", "error", socket.user?.email, jobid, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
@@ -289,7 +289,7 @@ const redisSocketEvents = ({
|
||||
});
|
||||
} catch (error) {
|
||||
FortellisLogger(socket, "error", `Error during Fortellis export : ${error.message}`);
|
||||
logger.log("fortellis-selectd-customer-error", "error", null, null, {
|
||||
logger.log("fortellis-selectd-customer-error", "error", socket.user?.email, jobid, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
@@ -301,7 +301,7 @@ const redisSocketEvents = ({
|
||||
callback(allocations);
|
||||
} catch (error) {
|
||||
FortellisLogger(socket, "error", `Error during Fortellis export : ${error.message}`);
|
||||
logger.log("fortellis-selectd-customer-error", "error", null, null, {
|
||||
logger.log("fortellis-selectd-customer-error", "error", socket.user?.email, jobid, {
|
||||
message: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user