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

@@ -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.
return departmentIds2 && departmentIds2[0] && departmentIds2[0].id; //TODO: This makes the assumption that there is only 1 department.
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(