WIP Get Makes
This commit is contained in:
@@ -5,6 +5,12 @@ const CdkWsdl = require("./cdk-wsdl").default;
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const { CDK_CREDENTIALS, CheckCdkResponseForError } = require("./cdk-wsdl");
|
||||
const {
|
||||
MakeFortellisCall,
|
||||
FortellisActions,
|
||||
GetAuthToken,
|
||||
GetDepartmentId
|
||||
} = require("../fortellis/fortellis-helpers");
|
||||
|
||||
// exports.default = async function (socket, cdk_dealerid) {
|
||||
// try {
|
||||
@@ -105,3 +111,85 @@ async function GetCdkMakes(req, cdk_dealerid) {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function GetFortellisMakes(req, cdk_dealerid) {
|
||||
logger.log("fortellis-replace-makes-models", "DEBUG", req.user.email, null, {
|
||||
cdk_dealerid
|
||||
});
|
||||
try {
|
||||
const result = await MakeFortellisCall({
|
||||
...FortellisActions.GetMakeModel,
|
||||
headers: {},
|
||||
redisHelpers: {
|
||||
setSessionTransactionData: () => {
|
||||
return null;
|
||||
},
|
||||
getSessionTransactionData: () => {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
socket: { emit: () => null },
|
||||
jobid: null,
|
||||
body: {},
|
||||
SubscriptionObject: {
|
||||
SubscriptionID: cdk_dealerid
|
||||
}
|
||||
});
|
||||
|
||||
logger.log("fortellis-replace-makes-models-response", "ERROR", req.user.email, null, {
|
||||
cdk_dealerid,
|
||||
xml: result
|
||||
});
|
||||
return result.data;
|
||||
} catch (error) {
|
||||
logger.log("fortellis-replace-makes-models-error", "ERROR", req.user.email, null, {
|
||||
cdk_dealerid,
|
||||
error
|
||||
});
|
||||
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
exports.fortellis = async function ReloadFortellisMakes(req, res) {
|
||||
const { bodyshopid, cdk_dealerid } = req.body;
|
||||
try {
|
||||
//Query all CDK Models
|
||||
const newList = await GetFortellisMakes(req, cdk_dealerid);
|
||||
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
const deleteResult = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.DELETE_ALL_DMS_VEHICLES, {});
|
||||
|
||||
//Insert the new ones.
|
||||
|
||||
const insertResult = await client.setHeaders({ Authorization: BearerToken }).request(queries.INSERT_DMS_VEHICLES, {
|
||||
vehicles: newList.map((i) => {
|
||||
return {
|
||||
bodyshopid,
|
||||
makecode: i.makeCode,
|
||||
modelcode: i.modelCode,
|
||||
make: i.makeFullName,
|
||||
model: i.modelFullName
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
logger.log("cdk-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, {
|
||||
cdk_dealerid,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
res.status(500).json(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,13 +9,13 @@ const logger = require("../utils/logger");
|
||||
const uuid = require("uuid").v4;
|
||||
const AxiosLib = require("axios").default;
|
||||
const axios = AxiosLib.create();
|
||||
const axiosCurlirize = require('axios-curlirize').default;
|
||||
const axiosCurlirize = require("axios-curlirize").default;
|
||||
|
||||
// Custom error class for Fortellis API errors
|
||||
class FortellisApiError extends Error {
|
||||
constructor(message, details) {
|
||||
super(message);
|
||||
this.name = 'FortellisApiError';
|
||||
this.name = "FortellisApiError";
|
||||
this.reqId = details.reqId;
|
||||
this.url = details.url;
|
||||
this.apiName = details.apiName;
|
||||
@@ -63,12 +63,14 @@ async function GetAuthToken() {
|
||||
return access_token;
|
||||
}
|
||||
|
||||
async function FetchSubscriptions({ redisHelpers, socket, jobid }) {
|
||||
async function FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject }) {
|
||||
try {
|
||||
const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
||||
|
||||
//Get Subscription ID from Transaction Envelope
|
||||
const { SubscriptionID } = await getSessionTransactionData(socket.id, getTransactionType(jobid), `txEnvelope`);
|
||||
const { SubscriptionID } = SubscriptionObject
|
||||
? SubscriptionObject
|
||||
: await getSessionTransactionData(socket.id, getTransactionType(jobid), `txEnvelope`);
|
||||
if (!SubscriptionID) {
|
||||
throw new Error("Subscription ID not found in transaction envelope.");
|
||||
}
|
||||
@@ -89,13 +91,15 @@ async function FetchSubscriptions({ redisHelpers, socket, jobid }) {
|
||||
headers: { Authorization: `Bearer ${access_token}` }
|
||||
});
|
||||
const SubscriptionMeta = subscriptions.data.subscriptions.find((s) => s.subscriptionId === SubscriptionID);
|
||||
await setSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(jobid),
|
||||
FortellisCacheEnums.SubscriptionMeta,
|
||||
SubscriptionMeta,
|
||||
defaultFortellisTTL
|
||||
);
|
||||
if (setSessionTransactionData) {
|
||||
await setSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(jobid),
|
||||
FortellisCacheEnums.SubscriptionMeta,
|
||||
SubscriptionMeta,
|
||||
defaultFortellisTTL
|
||||
);
|
||||
}
|
||||
return SubscriptionMeta;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -111,16 +115,10 @@ async function GetDepartmentId({ apiName, debug = false, SubscriptionMeta }) {
|
||||
if (debug) {
|
||||
console.log("API Names & Departments ");
|
||||
console.log("===========");
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
SubscriptionMeta.apiDmsInfo,
|
||||
null,
|
||||
4
|
||||
)
|
||||
);
|
||||
console.log(JSON.stringify(SubscriptionMeta.apiDmsInfo, null, 4));
|
||||
console.log("===========");
|
||||
}
|
||||
//TODO: Verify how to select the correct department.
|
||||
//TODO: Verify how to select the correct department.
|
||||
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.
|
||||
|
||||
@@ -140,6 +138,7 @@ async function MakeFortellisCall({
|
||||
jobid,
|
||||
redisHelpers,
|
||||
socket,
|
||||
SubscriptionObject //This is used because of the get make models to bypass all of the redis calls.
|
||||
}) {
|
||||
const { setSessionTransactionData, getSessionTransactionData } = redisHelpers;
|
||||
|
||||
@@ -148,7 +147,7 @@ async function MakeFortellisCall({
|
||||
if (debug) logger.log(`Executing ${type} to ${fullUrl}`);
|
||||
const ReqId = uuid();
|
||||
const access_token = await GetAuthToken();
|
||||
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid });
|
||||
const SubscriptionMeta = await FetchSubscriptions({ redisHelpers, socket, jobid, SubscriptionObject });
|
||||
const DepartmentId = await GetDepartmentId({ apiName, debug, SubscriptionMeta });
|
||||
|
||||
if (debug) {
|
||||
@@ -168,7 +167,7 @@ async function MakeFortellisCall({
|
||||
Authorization: `Bearer ${access_token}`,
|
||||
"Subscription-Id": SubscriptionMeta.subscriptionId,
|
||||
"Request-Id": ReqId,
|
||||
...DepartmentId && { "Department-Id": DepartmentId },
|
||||
...(DepartmentId && { "Department-Id": DepartmentId }),
|
||||
...headers
|
||||
}
|
||||
});
|
||||
@@ -283,54 +282,61 @@ const FortellisActions = {
|
||||
type: "get",
|
||||
apiName: "Service Vehicle - Query Vehicles"
|
||||
},
|
||||
GetMakeModel: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/makemodel/v2/bulk"
|
||||
: "https://api.fortellis.io/cdk-test/drive/makemodel/v2",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Get Make Model Lite"
|
||||
},
|
||||
GetVehicleId: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/vehicle-ids/" //Request path params of vins
|
||||
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/vehicle-ids/",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Service Vehicle",
|
||||
apiName: "CDK Drive Post Service Vehicle"
|
||||
},
|
||||
GetVehicleById: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/" //Request path params of vehicleId
|
||||
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Service Vehicle",
|
||||
apiName: "CDK Drive Post Service Vehicle"
|
||||
},
|
||||
QueryCustomerByName: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/customerpost/v1/search"
|
||||
: "https://api.fortellis.io/cdk-test/drive/customerpost/v1/search",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Customer",
|
||||
apiName: "CDK Drive Post Customer"
|
||||
},
|
||||
ReadCustomer: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/customerpost/v1/" //Customer ID is request param.
|
||||
: "https://api.fortellis.io/cdk-test/drive/customerpost/v1/",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Customer",
|
||||
apiName: "CDK Drive Post Customer"
|
||||
},
|
||||
CreateCustomer: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/customerpost/v1/"
|
||||
: "https://api.fortellis.io/cdk-test/drive/customerpost/v1/",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Customer",
|
||||
apiName: "CDK Drive Post Customer"
|
||||
},
|
||||
InsertVehicle: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/"
|
||||
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Service Vehicle",
|
||||
apiName: "CDK Drive Post Service Vehicle"
|
||||
},
|
||||
UpdateVehicle: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/service-vehicle-mgmt/v2/"
|
||||
: "https://api.fortellis.io/cdk-test/drive/service-vehicle-mgmt/v2/",
|
||||
type: "put",
|
||||
apiName: "CDK Drive Post Service Vehicle",
|
||||
apiName: "CDK Drive Post Service Vehicle"
|
||||
},
|
||||
GetCOA: {
|
||||
type: "get",
|
||||
@@ -343,37 +349,36 @@ const FortellisActions = {
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/startWIP"
|
||||
: "https://api.fortellis.io/cdk-test/drive/glpost/startWIP",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Accounting GL",
|
||||
apiName: "CDK Drive Post Accounting GL"
|
||||
},
|
||||
TranBatchWip: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/transBatchWIP"
|
||||
: "https://api.fortellis.io/cdk-test/drive/glpost/transBatchWIP",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Accounting GL",
|
||||
apiName: "CDK Drive Post Accounting GL"
|
||||
},
|
||||
PostBatchWip: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/postBatchWIP"
|
||||
: "https://api.fortellis.io/cdk-test/drive/glpost/postBatchWIP",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Accounting GL",
|
||||
apiName: "CDK Drive Post Accounting GL"
|
||||
},
|
||||
QueryErrorWip: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/glpost/errWIP"
|
||||
: "https://api.fortellis.io/cdk-test/drive/glpost/errWIP",
|
||||
type: "get",
|
||||
apiName: "CDK Drive Post Accounting GL",
|
||||
apiName: "CDK Drive Post Accounting GL"
|
||||
},
|
||||
ServiceHistoryInsert: {
|
||||
url: isProduction
|
||||
? "https://api.fortellis.io/cdk/drive/post/service-vehicle-history-mgmt/v2/"
|
||||
: "https://api.fortellis.io/cdk-test/drive/post/service-vehicle-history-mgmt/v2/",
|
||||
type: "post",
|
||||
apiName: "CDK Drive Post Service Vehicle History",
|
||||
},
|
||||
|
||||
apiName: "CDK Drive Post Service Vehicle History"
|
||||
}
|
||||
};
|
||||
|
||||
const FortellisCacheEnums = {
|
||||
@@ -391,7 +396,7 @@ const FortellisCacheEnums = {
|
||||
DMSTransHeader: "DMSTransHeader",
|
||||
transWips: "transWips",
|
||||
DmsBatchTxnPost: "DmsBatchTxnPost",
|
||||
DMSVehHistory: "DMSVehHistory",
|
||||
DMSVehHistory: "DMSVehHistory"
|
||||
};
|
||||
|
||||
function constructFullUrl({ url, pathParams = "", requestSearchParams = [] }) {
|
||||
@@ -403,8 +408,6 @@ function constructFullUrl({ url, pathParams = "", requestSearchParams = [] }) {
|
||||
return fullUrl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
GetAuthToken,
|
||||
FortellisCacheEnums,
|
||||
@@ -412,5 +415,6 @@ module.exports = {
|
||||
FortellisActions,
|
||||
getTransactionType,
|
||||
defaultFortellisTTL,
|
||||
FortellisApiError
|
||||
FortellisApiError,
|
||||
GetDepartmentId
|
||||
};
|
||||
|
||||
@@ -318,8 +318,11 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, selectedCustome
|
||||
"ERROR",
|
||||
`DMS Batch Return code was not successful: ${DMSBatchTxn.rtnCode} - ${DMSBatchTxn.sendline}`
|
||||
);
|
||||
await InsertFailedExportLog({ socket, JobData, error: `DMS Batch Return code was not successful: ${DMSBatchTxn.rtnCode} - ${DMSBatchTxn.sendline}` });
|
||||
|
||||
await InsertFailedExportLog({
|
||||
socket,
|
||||
JobData,
|
||||
error: `DMS Batch Return code was not successful: ${DMSBatchTxn.rtnCode} - ${DMSBatchTxn.sendline}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
// CdkBase.createLogEvent(socket, "ERROR", `Error encountered in CdkSelectedCustomer.${ error } `);
|
||||
@@ -654,7 +657,7 @@ async function InsertDmsVehicle({ socket, redisHelpers, JobData, txEnvelope, DMS
|
||||
jobid: JobData.id,
|
||||
body: {
|
||||
dealer: {
|
||||
company: JobData.bodyshop.cdk_configuration.srcco || "77",
|
||||
//company: JobData.bodyshop.cdk_configuration.srcco || "77",
|
||||
// "dealNumber": "",
|
||||
// "dealerAssignedNumber": "82268",
|
||||
// "dealerDefined1": "2WDSP",
|
||||
@@ -1018,13 +1021,12 @@ async function InsertDmsStartWip({ socket, redisHelpers, JobData }) {
|
||||
// "rtnCode": "",
|
||||
// "sendline": "",
|
||||
// "groupName": "",
|
||||
"srcCo": JobData.bodyshop.cdk_configuration.srcco,
|
||||
"srcJrnl": txEnvelope.journal,
|
||||
"transID": "",
|
||||
"userID": "csr" || JobData.bodyshop.cdk_configuration.cashierid,
|
||||
"userName": "BSMS"
|
||||
},
|
||||
|
||||
srcCo: JobData.bodyshop.cdk_configuration.srcco,
|
||||
srcJrnl: txEnvelope.journal,
|
||||
transID: "",
|
||||
userID: "csr" || JobData.bodyshop.cdk_configuration.cashierid,
|
||||
userName: "BSMS"
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -1238,8 +1240,7 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) {
|
||||
socket,
|
||||
jobid: JobData.id,
|
||||
requestPathParams: DMSTransHeader.transID,
|
||||
body: {
|
||||
}
|
||||
body: {}
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -1252,11 +1253,13 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) {
|
||||
}
|
||||
|
||||
async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
|
||||
|
||||
let DMSTransHeader;
|
||||
try {
|
||||
DMSTransHeader = await redisHelpers.getSessionTransactionData(socket.id, getTransactionType(JobData.id), FortellisCacheEnums.DMSTransHeader);
|
||||
|
||||
DMSTransHeader = await redisHelpers.getSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(JobData.id),
|
||||
FortellisCacheEnums.DMSTransHeader
|
||||
);
|
||||
|
||||
const result = await MakeFortellisCall({
|
||||
...FortellisActions.PostBatchWip,
|
||||
@@ -1265,8 +1268,8 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
|
||||
socket,
|
||||
jobid: JobData.id,
|
||||
body: {
|
||||
"opCode": "D",
|
||||
"transID": DMSTransHeader.transID
|
||||
opCode: "D",
|
||||
transID: DMSTransHeader.transID
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
||||
@@ -8,6 +8,7 @@ const withUserGraphQLClientMiddleware = require("../middleware/withUserGraphQLCl
|
||||
router.use(validateFirebaseIdTokenMiddleware);
|
||||
|
||||
router.post("/getvehicles", withUserGraphQLClientMiddleware, cdkGetMake.default);
|
||||
router.post("/fortellis/getvehicles", withUserGraphQLClientMiddleware, cdkGetMake.fortellis);
|
||||
router.post("/calculate-allocations", withUserGraphQLClientMiddleware, cdkCalculateAllocations.defaultRoute);
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user