IO-233 Add customer insert actions.
This commit is contained in:
@@ -55,6 +55,10 @@ export function DmsContainer({ bodyshop, setBreadcrumbs, setSelectedHeader }) {
|
||||
socket.on("connected", () => {
|
||||
console.log("Connected again.");
|
||||
});
|
||||
socket.on("reconnect", () => {
|
||||
console.log("Connected again.");
|
||||
setLogs([]);
|
||||
});
|
||||
|
||||
socket.on("log-event", (payload) => {
|
||||
setLogs((logs) => {
|
||||
@@ -119,11 +123,11 @@ function LogLevelHierarchy(level) {
|
||||
case "TRACE":
|
||||
return "pink";
|
||||
case "DEBUG":
|
||||
return "orange";
|
||||
return "green";
|
||||
case "INFO":
|
||||
return "blue";
|
||||
case "WARNING":
|
||||
return "yellow";
|
||||
return "orange";
|
||||
case "ERROR":
|
||||
return "red";
|
||||
default:
|
||||
|
||||
@@ -61,20 +61,51 @@ exports.default = async function (socket, jobid) {
|
||||
|
||||
//Array
|
||||
const strIDS = await FindCustomerIdFromDms(socket, JobData);
|
||||
if (strIDS.length > 0) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `{8.2} Customer ID(s) found.`);
|
||||
if (strIDS && strIDS.length > 0) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{8.2} Customer ID(s) found. strIDS: ${JSON.stringify(
|
||||
strIDS,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
} else {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{8.5} Customer ID(s) *not* found.`
|
||||
);
|
||||
|
||||
//Create a customer number, then use that to insert the customer record.
|
||||
const newCustomerNumber = await GenerateCustomerNumberFromDms(
|
||||
socket,
|
||||
JobData
|
||||
);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{10.1} New Customer number generated. newCustomerNumber: ${newCustomerNumber}`
|
||||
);
|
||||
|
||||
//Use the new customer number to insert the customer record.
|
||||
clADPC = await CreateCustomerInDms(socket, JobData, newCustomerNumber);
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{11.1} New Customer inserted. customer: ${JSON.stringify(
|
||||
clADPC,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{1.2} clVFV DMSVid does exist. clVFV: ${JSON.stringify(
|
||||
`{1.1} clVFV DMSVid does exist. clVFV: ${JSON.stringify(
|
||||
clVFV,
|
||||
null,
|
||||
2
|
||||
@@ -135,6 +166,125 @@ async function QueryJobData(socket, jobid) {
|
||||
return result.jobs_by_pk;
|
||||
}
|
||||
|
||||
async function CreateCustomerInDms(socket, JobData, newCustomerNumber) {
|
||||
CdkBase.createLogEvent(socket, "DEBUG", `{10} Begin Create Customer in DMS`);
|
||||
|
||||
try {
|
||||
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
||||
CdkWsdl.CustomerInsertUpdate
|
||||
);
|
||||
const soapResponseCustomerInsertUpdate =
|
||||
await soapClientCustomerInsertUpdate.insertAsync(
|
||||
{
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
||||
arg2: { userId: null },
|
||||
arg3: {
|
||||
//Copied the required fields from the other integration.
|
||||
//TODO: Verify whether we need to bring more information in.
|
||||
id: { value: newCustomerNumber },
|
||||
address: {
|
||||
city: JobData.ownr_city,
|
||||
country: null,
|
||||
postalcode: JobData.ownr_zip,
|
||||
stateOrProvince: JobData.ownr_st,
|
||||
},
|
||||
contactInfo: {
|
||||
mainTelephoneNumber: { main: true, value: JobData.ownr_ph1 },
|
||||
},
|
||||
demographics: null,
|
||||
name1: {
|
||||
companyname: null,
|
||||
firstName: JobData.ownr_fn,
|
||||
fullname: null,
|
||||
lastName: JobData.ownr_ln,
|
||||
middleName: null,
|
||||
nameType: "Person",
|
||||
suffix: null,
|
||||
title: null,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseCustomerInsertUpdate;
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientCustomerInsertUpdate.insertAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
const customer = result && result.return;
|
||||
return customer;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in CreateCustomerInDms - ${JSON.stringify(error, null, 2)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function GenerateCustomerNumberFromDms(socket, JobData) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"DEBUG",
|
||||
`{10} Begin Generate Customer Number from DMS`
|
||||
);
|
||||
|
||||
try {
|
||||
const soapClientCustomerInsertUpdate = await soap.createClientAsync(
|
||||
CdkWsdl.CustomerInsertUpdate
|
||||
);
|
||||
const soapResponseCustomerInsertUpdate =
|
||||
await soapClientCustomerInsertUpdate.getCustomerNumberAsync(
|
||||
{
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
||||
arg2: { userId: null },
|
||||
},
|
||||
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerInsertUpdate);
|
||||
const [
|
||||
result, //rawResponse, soapheader, rawRequest
|
||||
] = soapResponseCustomerInsertUpdate;
|
||||
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
`soapClientCustomerInsertUpdate.getCustomerNumberAsync Result ${JSON.stringify(
|
||||
result,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
const customerNumber =
|
||||
result && result.return && result.return.customerNumber;
|
||||
return customerNumber;
|
||||
} catch (error) {
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"ERROR",
|
||||
`Error in GenerateCustomerNumberFromDms - ${JSON.stringify(
|
||||
error,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
async function FindCustomerIdFromDms(socket, JobData) {
|
||||
const ownerName = `${JobData.ownr_ln},${JobData.ownr_fn}`;
|
||||
CdkBase.createLogEvent(
|
||||
@@ -148,12 +298,12 @@ async function FindCustomerIdFromDms(socket, JobData) {
|
||||
CdkWsdl.CustomerSearch
|
||||
);
|
||||
const soapResponseCustomerSearch =
|
||||
await soapClientCustomerSearch.executeSearchBulkAsync(
|
||||
await soapClientCustomerSearch.executeSearchAsync(
|
||||
{
|
||||
arg0: CDK_CREDENTIALS,
|
||||
arg1: { id: JobData.bodyshop.cdk_dealerid },
|
||||
arg1: { dealerId: JobData.bodyshop.cdk_dealerid }, //TODO: Verify why this does not follow the other standards.
|
||||
arg2: {
|
||||
verb: "EXACT",
|
||||
// verb: "EXACT",
|
||||
key: ownerName,
|
||||
},
|
||||
},
|
||||
@@ -161,19 +311,9 @@ async function FindCustomerIdFromDms(socket, JobData) {
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseCustomerSearch);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseCustomerSearch;
|
||||
//result format
|
||||
// return: [
|
||||
// {
|
||||
// code: 'success',
|
||||
// carInvStockNo: '',
|
||||
// errorLevel: '0',
|
||||
// errorMessage: '',
|
||||
// newId: 'Y',
|
||||
// vehiclesVehId: 'HM263407'
|
||||
// }
|
||||
// ]
|
||||
const [
|
||||
result, // rawResponse, soapheader, rawRequest
|
||||
] = soapResponseCustomerSearch;
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"TRACE",
|
||||
@@ -191,6 +331,7 @@ async function FindCustomerIdFromDms(socket, JobData) {
|
||||
"ERROR",
|
||||
`Error in FindCustomerIdFromDms - ${JSON.stringify(error, null, 2)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,8 +360,9 @@ async function FindVehicleInDms(socket, JobData, clVFV) {
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseVehicleInsertUpdate;
|
||||
const [
|
||||
result, //rawResponse, soapheader, rawRequest
|
||||
] = soapResponseVehicleInsertUpdate;
|
||||
//result format
|
||||
// return: [
|
||||
// {
|
||||
@@ -249,6 +391,7 @@ async function FindVehicleInDms(socket, JobData, clVFV) {
|
||||
"ERROR",
|
||||
`Error in FindVehicleInDms - ${JSON.stringify(error, null, 2)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,8 +417,9 @@ async function CalculateDmsVid(socket, JobData) {
|
||||
{}
|
||||
);
|
||||
CheckCdkResponseForError(socket, soapResponseVehicleInsertUpdate);
|
||||
const [result, rawResponse, soapheader, rawRequest] =
|
||||
soapResponseVehicleInsertUpdate;
|
||||
const [
|
||||
result, //rawResponse, soapheader, rawRequest
|
||||
] = soapResponseVehicleInsertUpdate;
|
||||
//result format
|
||||
// return: [
|
||||
// {
|
||||
@@ -304,15 +448,32 @@ async function CalculateDmsVid(socket, JobData) {
|
||||
"ERROR",
|
||||
`Error in CalculateDmsVid - ${JSON.stringify(error, null, 2)}`
|
||||
);
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function CheckCdkResponseForError(socket, soapResponse) {
|
||||
const ResultToCheck = Array.isArray(soapResponse[0].return)
|
||||
if (!soapResponse[0]) {
|
||||
//The response was null, this might be ok, it might not.
|
||||
CdkBase.createLogEvent(
|
||||
socket,
|
||||
"WARNING",
|
||||
`Warning detected in CDK Response - it appears to be null. Stack: ${
|
||||
new Error().stack
|
||||
}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const ResultToCheck = Array.isArray(soapResponse[0] && soapResponse[0].return)
|
||||
? soapResponse[0].return[0]
|
||||
: soapResponse[0].return;
|
||||
|
||||
if (ResultToCheck.errorLevel === 0 || ResultToCheck.errorLevel === "0")
|
||||
if (
|
||||
ResultToCheck.errorLevel === 0 ||
|
||||
ResultToCheck.errorLevel === "0" ||
|
||||
ResultToCheck.code === "success"
|
||||
)
|
||||
//TODO: Verify that this is the best way to detect errors.
|
||||
return;
|
||||
else {
|
||||
@@ -326,9 +487,12 @@ function CheckCdkResponseForError(socket, soapResponse) {
|
||||
)}`
|
||||
);
|
||||
|
||||
throw {
|
||||
errorLevel: ResultToCheck.errorLevel,
|
||||
errorMessage: ResultToCheck.errorMessage,
|
||||
};
|
||||
throw new Error(
|
||||
`Error found while validating CDK response for ${JSON.stringify(
|
||||
ResultToCheck,
|
||||
null,
|
||||
2
|
||||
)}:`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const path = require("path");
|
||||
const _ = require("lodash");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
@@ -72,6 +71,9 @@ function createLogEvent(socket, level, message) {
|
||||
message,
|
||||
});
|
||||
}
|
||||
// if (level === "ERROR") {
|
||||
// throw new Error(message);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user