Additional Fortellis functionality on delete.
This commit is contained in:
@@ -252,80 +252,68 @@ async function FortellisSelectedCustomer({ socket, redisHelpers, selectedCustome
|
||||
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{5.1} Creating Transaction with ID ${DMSTransHeader.transID}`);
|
||||
|
||||
// const DMSBatchTxn = await InsertDmsBatchWip({ socket, redisHelpers, JobData });
|
||||
// await setSessionTransactionData(
|
||||
// socket.id,
|
||||
// getTransactionType(jobid),
|
||||
// FortellisCacheEnums.DMSBatchTxn,
|
||||
// DMSBatchTxn,
|
||||
// defaultFortellisTTL
|
||||
// );
|
||||
|
||||
if (DMSTransHeader.rtnCode === "0") {
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6} Attempting to post Transaction with ID ${DMSTransHeader.transID}`);
|
||||
try {
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6} Attempting to post Transaction with ID ${DMSTransHeader.transID}`);
|
||||
|
||||
const DmsBatchTxnPost = await PostDmsBatchWip({ socket, redisHelpers, JobData });
|
||||
await setSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(jobid),
|
||||
FortellisCacheEnums.DmsBatchTxnPost,
|
||||
DmsBatchTxnPost,
|
||||
defaultFortellisTTL
|
||||
);
|
||||
|
||||
if (DmsBatchTxnPost.rtnCode === "0") {
|
||||
//TODO: Validate this is a string and not #
|
||||
//something
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6} Successfully posted transaction to DMS.`);
|
||||
|
||||
await MarkJobExported({ socket, jobid: JobData.id });
|
||||
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{5} Updating Service Vehicle History.`);
|
||||
const DMSVehHistory = await InsertServiceVehicleHistory({ socket, redisHelpers, JobData });
|
||||
const DmsBatchTxnPost = await PostDmsBatchWip({ socket, redisHelpers, JobData }); // 2 in 1 call that includes a post and the transactions.
|
||||
await setSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(jobid),
|
||||
FortellisCacheEnums.DMSVehHistory,
|
||||
DMSVehHistory,
|
||||
FortellisCacheEnums.DmsBatchTxnPost,
|
||||
DmsBatchTxnPost,
|
||||
defaultFortellisTTL
|
||||
);
|
||||
socket.emit("export-success", JobData.id);
|
||||
} else {
|
||||
//Get the error code
|
||||
|
||||
|
||||
if (DmsBatchTxnPost.rtnCode === "0") {
|
||||
//TODO: Validate this is a string and not #
|
||||
//something
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6} Successfully posted transaction to DMS.`);
|
||||
|
||||
await MarkJobExported({ socket, jobid: JobData.id, JobData });
|
||||
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{5} Updating Service Vehicle History.`);
|
||||
const DMSVehHistory = await InsertServiceVehicleHistory({ socket, redisHelpers, JobData });
|
||||
await setSessionTransactionData(
|
||||
socket.id,
|
||||
getTransactionType(jobid),
|
||||
FortellisCacheEnums.DMSVehHistory,
|
||||
DMSVehHistory,
|
||||
defaultFortellisTTL
|
||||
);
|
||||
socket.emit("export-success", JobData.id);
|
||||
} else {
|
||||
//There was something wrong. Throw an error to trigger clean up.
|
||||
throw new Error("Error posting DMS Batch Transaction");
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
//Clean up the transaction and insert a faild error code
|
||||
// //Get the error code
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6.1} Getting errors for Transaction ID ${DMSTransHeader.transID}`);
|
||||
|
||||
await QueryDmsErrWip({ socket, redisHelpers, JobData });
|
||||
|
||||
const DmsError = await QueryDmsErrWip({ socket, redisHelpers, JobData });
|
||||
// //Delete the transaction
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{{ 6.2 } Deleting Transaction ID ${DMSTransHeader.transID}`);
|
||||
CreateFortellisLogEvent(socket, "DEBUG", `{6.2} Deleting Transaction ID ${DMSTransHeader.transID}`);
|
||||
|
||||
const DmsBatchTxnDelete = await DeleteDmsWip({ socket, redisHelpers, JobData });
|
||||
await DeleteDmsWip({ socket, redisHelpers, JobData });
|
||||
|
||||
DmsError.errMsg.map(
|
||||
DmsError.errLine.map(
|
||||
(e) =>
|
||||
e !== null &&
|
||||
e !== "" &&
|
||||
CreateFortellisLogEvent(socket, "ERROR", `Error(s) encountered in posting transaction.${e} `)
|
||||
CreateFortellisLogEvent(socket, "ERROR", `Error encountered in posting transaction => ${e} `)
|
||||
);
|
||||
await InsertFailedExportLog({
|
||||
socket,
|
||||
JobData,
|
||||
error: DmsError.errMsg
|
||||
error: DmsError.errLine
|
||||
});
|
||||
}
|
||||
} else {
|
||||
//Creating transaction failed.
|
||||
CreateFortellisLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`DMS Batch Return code was not successful: ${DMSTransHeader.rtnCode} - ${DMSTransHeader.sendline}`
|
||||
);
|
||||
await InsertFailedExportLog({
|
||||
socket,
|
||||
JobData,
|
||||
error: `DMS Batch Return code was not successful: ${DMSTransHeader.rtnCode} - ${DMSTransHeader.sendline}`
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
CreateFortellisLogEvent(socket, "ERROR", `Error in FortellisSelectedCustomer - ${error} `, {
|
||||
@@ -1231,7 +1219,6 @@ async function PostDmsBatchWip({ socket, redisHelpers, JobData }) {
|
||||
transID: DMSTransHeader.transID,
|
||||
transWipReqList: await GenerateTransWips({ socket, redisHelpers, JobData })
|
||||
},
|
||||
overrideDepartmentId: "D100152198"
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -1260,7 +1247,6 @@ async function QueryDmsErrWip({ socket, redisHelpers, JobData }) {
|
||||
jobid: JobData.id,
|
||||
requestPathParams: DMSTransHeader.transID,
|
||||
body: {},
|
||||
overrideDepartmentId: "D100152198"
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -1282,7 +1268,7 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
|
||||
);
|
||||
|
||||
const result = await MakeFortellisCall({
|
||||
...FortellisActions.PostBatchWip,
|
||||
...FortellisActions.DeleteTranWip,
|
||||
headers: {},
|
||||
redisHelpers,
|
||||
socket,
|
||||
@@ -1291,7 +1277,6 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
|
||||
opCode: "D",
|
||||
transID: DMSTransHeader.transID
|
||||
},
|
||||
overrideDepartmentId: "D100152198"
|
||||
});
|
||||
return result;
|
||||
} catch (error) {
|
||||
@@ -1303,7 +1288,7 @@ async function DeleteDmsWip({ socket, redisHelpers, JobData }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function MarkJobExported({ socket, jobid }) {
|
||||
async function MarkJobExported({ socket, jobid, JobData }) {
|
||||
CreateFortellisLogEvent(socket, "ERROR", `Marking job as exported for id ${jobid}`);
|
||||
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {});
|
||||
@@ -1315,11 +1300,11 @@ async function MarkJobExported({ socket, jobid }) {
|
||||
.request(queries.MARK_JOB_EXPORTED, {
|
||||
jobId: jobid,
|
||||
job: {
|
||||
status: socket.JobData.bodyshop.md_ro_statuses.default_exported || "Exported*",
|
||||
status: JobData.bodyshop.md_ro_statuses.default_exported || "Exported*",
|
||||
date_exported: new Date()
|
||||
},
|
||||
log: {
|
||||
bodyshopid: socket.JobData.bodyshop.id,
|
||||
bodyshopid: JobData.bodyshop.id,
|
||||
jobid: jobid,
|
||||
successful: true,
|
||||
useremail: socket.user.email,
|
||||
@@ -1343,13 +1328,13 @@ async function InsertFailedExportLog({ socket, JobData, error }) {
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: `Bearer ${currentToken}` })
|
||||
.request(queries.INSERT_EXPORT_LOG, {
|
||||
log: {
|
||||
logs: [{
|
||||
bodyshopid: JobData.bodyshop.id,
|
||||
jobid: JobData.id,
|
||||
successful: false,
|
||||
message: JSON.stringify(error),
|
||||
useremail: socket.user.email
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user