Resolve PPG data pump issue.

This commit is contained in:
Patrick Fic
2022-09-20 15:30:32 -07:00
parent 78a04067c5
commit cccd025a24

View File

@@ -24,9 +24,8 @@ exports.mixdataUpload = async (req, res) => {
}); });
try { try {
req.files.forEach(async (element) => { for (const element of req.files) {
const b = Buffer.from(element.buffer); const b = Buffer.from(element.buffer);
console.log(b.toString());
const inboundRequest = await xml2js.parseStringPromise(b.toString(), { const inboundRequest = await xml2js.parseStringPromise(b.toString(), {
explicitArray: false, explicitArray: false,
@@ -59,23 +58,24 @@ exports.mixdataUpload = async (req, res) => {
ScaleType, ScaleType,
jobHash jobHash
); );
const foundJobs = MixDataArray.filter((m) => m.jobid);
const MixDataQuery = ` const MixDataQuery = `
mutation UPSERT_MIXDATA{ mutation UPSERT_MIXDATA{
${MixDataArray.map((md, idx) => ${foundJobs
GenerateGqlForMixData(md, idx) .map((md, idx) => GenerateGqlForMixData(md, idx))
).join(" ")} .join(" ")}
} }
`; `;
if (foundJobs.length > 1) {
const resp = await client.request(MixDataQuery); const resp = await client.request(MixDataQuery);
}
//Process the list of ROs and return an object to generate the queries. //Process the list of ROs and return an object to generate the queries.
} }
}); }
res.sendStatus(200); res.sendStatus(200);
} catch (error) { } catch (error) {
res.status(500).JSON(error); res.status(500).json(error);
logger.log("job-mixdata-upload-error", "ERROR", null, null, { logger.log("job-mixdata-upload-error", "ERROR", null, null, {
error: error.message, error: error.message,
...error, ...error,
@@ -98,7 +98,7 @@ function DetermineScaleType(inboundRequest) {
function GetListOfRos(inboundRequest, ScaleType) { function GetListOfRos(inboundRequest, ScaleType) {
if (ScaleType.company === "PPG" && ScaleType.version === "1.3.0") { if (ScaleType.company === "PPG" && ScaleType.version === "1.3.0") {
return inboundRequest.PPG.DataExportInterface.ROData.RepairOrders.RO.map( return inboundRequest.PPG.MixDataInterface.ROData.RepairOrders.RO.map(
(r) => r.RONumber (r) => r.RONumber
); );
} }
@@ -106,11 +106,11 @@ function GetListOfRos(inboundRequest, ScaleType) {
function GenerateMixDataArray(inboundRequest, ScaleType, jobHash) { function GenerateMixDataArray(inboundRequest, ScaleType, jobHash) {
if (ScaleType.company === "PPG" && ScaleType.version === "1.3.0") { if (ScaleType.company === "PPG" && ScaleType.version === "1.3.0") {
return inboundRequest.PPG.DataExportInterface.ROData.RepairOrders.RO.map( return inboundRequest.PPG.MixDataInterface.ROData.RepairOrders.RO.map(
(r) => { (r) => {
return { return {
jobid: jobHash[r.RONumber].jobid, jobid: jobHash[r.RONumber]?.jobid,
id: jobHash[r.RONumber].mixdataid, id: jobHash[r.RONumber]?.mixdataid,
mixdata: r, mixdata: r,
totalliquidcost: r.TotalLiquidCost, totalliquidcost: r.TotalLiquidCost,
totalsundrycost: r.TotalSundryCost, totalsundrycost: r.TotalSundryCost,