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) {
////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}` });
}
};
@@ -33,6 +34,7 @@ exports.default = async function (socket, jobid, isFortellis = false) {
////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}`);
}
};

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 (debug) {
console.log("API Names & Departments ");
@@ -122,7 +122,12 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) {
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.
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.
}
}
//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,
redisHelpers,
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;
@@ -148,7 +154,7 @@ async function MakeFortellisCall({
const ReqId = uuid();
const access_token = await GetAuthToken();
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) {
console.log(

View File

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