Add department overrides.

This commit is contained in:
Patrick Fic
2025-11-05 13:23:24 -08:00
parent c6d083ce02
commit a16c680d04
3 changed files with 91 additions and 79 deletions

View File

@@ -21,6 +21,7 @@ exports.defaultRoute = async function (req, res) {
} catch (error) { } catch (error) {
////console.log(error); ////console.log(error);
WsLogger.createLogEvent(req, "ERROR", `Error encountered in CdkCalculateAllocations. ${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}` }); res.status(500).json({ error: `Error encountered in CdkCalculateAllocations. ${error}` });
} }
}; };
@@ -33,6 +34,7 @@ exports.default = async function (socket, jobid, isFortellis = false) {
////console.log(error); ////console.log(error);
const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent; const loggingFunction = isFortellis ? CreateFortellisLogEvent : WsLogger.createLogEvent;
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`); loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error}`);
loggingFunction(socket, "ERROR", `Error encountered in CdkCalculateAllocations. ${error.stack}`);
} }
}; };

View File

@@ -110,7 +110,7 @@ async function FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObj
} }
} }
async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) { async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta, overrideDepartmentId }) {
if (!apiName) throw new Error("apiName not provided. Unable to get department without apiName."); if (!apiName) throw new Error("apiName not provided. Unable to get department without apiName.");
if (debug) { if (debug) {
console.log("API Names & Departments "); console.log("API Names & Departments ");
@@ -122,7 +122,12 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) {
const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object. const departmentIds2 = SubscriptionMeta.apiDmsInfo //Get the subscription object.
.find((info) => info.name === apiName)?.departments; //Departments are categorized by API name and have an array of departments. .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.
} else {
return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department. return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department.
}
} }
//Highest level function call to make a call to fortellis. This should be the only call required, and it will handle all the logic for making the call. //Highest level function call to make a call to fortellis. This should be the only call required, and it will handle all the logic for making the call.
@@ -138,7 +143,8 @@ async function MakeFortellisCall({
jobid, jobid,
redisHelpers, redisHelpers,
socket, socket,
SubscriptionObject //This is used because of the get make models to bypass all of the redis calls. 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;
@@ -148,7 +154,7 @@ async function MakeFortellisCall({
const ReqId = uuid(); const ReqId = uuid();
const access_token = await GetAuthToken(); const access_token = await GetAuthToken();
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject }); const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject });
const DepartmentId = await GetDepartmentId({ apiName, debug, SubscriptionMeta }); const DepartmentId = await GetDepartmentId({ apiName, debug, SubscriptionMeta, overrideDepartmentId });
if (debug) { if (debug) {
console.log( console.log(

View File

@@ -1015,34 +1015,35 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
socket, socket,
jobid: JobData.id, jobid: JobData.id,
body: { body: {
// acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"), acctgDate: moment().tz(JobData.bodyshop.timezone).format("YYYY-MM-DD"),
// desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""), desc: txEnvelope.story && txEnvelope.story.replace(replaceSpecialRegex, ""),
// docType: "10", docType: "10",
// m13Flag: "0",
// refer: JobData.ro_number,
// // "rtnCode": "",
// // "sendline": "",
// // "groupName": "",
// srcCo: JobData.bodyshop.cdk_configuration.srcco,
// srcJrnl: txEnvelope.journal,
// transID: "",
// userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid,
// userName: "PROGRAM, PARTNER"
acctgDate: "2025-07-07",
desc: "DOCUMENT DESC. OPTIONAL REQUIREMENT",
docType: "3",
m13Flag: "0", m13Flag: "0",
refer: "707MISC01", refer: JobData.ro_number,
rtnCode: "", // "rtnCode": "",
sendline: "", // "sendline": "",
groupName: "", // "groupName": "",
srcCo: "77", srcCo: JobData.bodyshop.cdk_configuration.srcco,
srcJrnl: "80", srcJrnl: txEnvelope.journal,
transID: "", transID: "",
userID: "partprgm", userID: "partprgm" || JobData.bodyshop.cdk_configuration.cashierid,
userName: "PROGRAM, PARTNER" userName: "PROGRAM, PARTNER"
}
// acctgDate: "2025-07-07",
// desc: "DOCUMENT DESC. OPTIONAL REQUIREMENT",
// docType: "3",
// m13Flag: "0",
// refer: "707MISC01",
// rtnCode: "",
// sendline: "",
// groupName: "",
// srcCo: "77",
// srcJrnl: "80",
// transID: "",
// userID: "partprgm",
// userName: "PROGRAM, PARTNER"
},
//overrideDepartmentId: "D100152198" //TODO: REMOVE AFTER TESTING
}); });
return result; return result;
} catch (error) { } catch (error) {
@@ -1229,7 +1230,8 @@ async function PostDmsBatchWip({ socket, redisHelpers, JobData }) {
opCode: "P", opCode: "P",
transID: DMSTransHeader.transID, transID: DMSTransHeader.transID,
transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData }) transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData })
} },
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {
@@ -1257,7 +1259,8 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) {
socket, socket,
jobid: JobData.id, jobid: JobData.id,
requestPathParams: DMSTransHeader.transID, requestPathParams: DMSTransHeader.transID,
body: {} body: {},
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {
@@ -1287,7 +1290,8 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
body: { body: {
opCode: "D", opCode: "D",
transID: DMSTransHeader.transID transID: DMSTransHeader.transID
} },
overrideDepartmentId: "D100152198"
}); });
return result; return result;
} catch (error) { } catch (error) {