feature/IO-3255-simplified-parts-management - Expand Joblines Parser, remove body-parser reference in favor of express.raw
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
const client = require("../../../graphql-client/graphql-client").client;
|
||||
const { parseXml, normalizeXmlObject } = require("../partsManagementUtils");
|
||||
const { toArray } = require("lodash");
|
||||
|
||||
// GraphQL Queries and Mutations
|
||||
const {
|
||||
@@ -373,37 +374,48 @@ const extractVehicleData = (rq, shopId) => {
|
||||
* @returns {object[]} Array of job line objects.
|
||||
*/
|
||||
const extractJobLines = (rq) => {
|
||||
const damageLines = Array.isArray(rq.DamageLineInfo) ? rq.DamageLineInfo : [rq.DamageLineInfo];
|
||||
const damageLines = toArray(rq.DamageLineInfo);
|
||||
if (damageLines.length === 0) {
|
||||
return []; // Or throw if required
|
||||
}
|
||||
|
||||
return damageLines.map((line) => {
|
||||
const partInfo = line.PartInfo || {};
|
||||
const laborInfo = line.LaborInfo || {};
|
||||
const subletInfo = line.SubletInfo || {};
|
||||
|
||||
let jobLineType = "PART";
|
||||
if (Object.keys(subletInfo).length > 0) jobLineType = "SUBLET";
|
||||
else if (Object.keys(laborInfo).length > 0 && Object.keys(partInfo).length === 0) jobLineType = "LABOR";
|
||||
|
||||
const jobLine = {
|
||||
line_no: parseInt(line.LineNum, 10),
|
||||
unq_seq: parseInt(line.UniqueSequenceNum, 10),
|
||||
line_no: parseInt(line.LineNum || 0, 10),
|
||||
unq_seq: parseInt(line.UniqueSequenceNum || 0, 10),
|
||||
status: line.LineStatusCode || null,
|
||||
line_desc: line.LineDesc || null,
|
||||
part_type: line.PartInfo?.PartType || null,
|
||||
part_qty: parseFloat(line.PartInfo?.Quantity || 0),
|
||||
oem_partno: line.PartInfo?.OEMPartNum || null,
|
||||
db_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||
act_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||
mod_lbr_ty: line.LaborInfo?.LaborType || null,
|
||||
mod_lb_hrs: parseFloat(line.LaborInfo?.LaborHours || 0),
|
||||
lbr_op: line.LaborInfo?.LaborOperation || null,
|
||||
lbr_amt: parseFloat(line.LaborInfo?.LaborAmt || 0),
|
||||
notes: line.LineMemo || null,
|
||||
manual_line: line.ManualLineInd || null
|
||||
// taxable_ind: line.PartInfo?.TaxableInd || null,
|
||||
// automated_entry: line.AutomatedEntry || null
|
||||
line_desc: line.LineDesc || null
|
||||
// line_type: jobLineType // New field for clarity
|
||||
};
|
||||
|
||||
// TODO: Commented out as not clear if needed for version 1, this only applies to Imex and not rome on the front
|
||||
// end
|
||||
// if ((jobLine.part_type === "PASL" || jobLine.part_type === "PAS") && jobLine.lbr_op !== "OP11") {
|
||||
// jobLine.tax_part = true;
|
||||
// }
|
||||
// if (line.db_ref === "900510") {
|
||||
// jobLine.tax_part = true;
|
||||
// }
|
||||
if (jobLineType === "PART") {
|
||||
jobLine.part_type = partInfo.PartType || null;
|
||||
jobLine.part_qty = parseFloat(partInfo.Quantity || 0);
|
||||
jobLine.oem_partno = partInfo.OEMPartNum || null;
|
||||
jobLine.db_price = parseFloat(partInfo.PartPrice || 0);
|
||||
jobLine.act_price = parseFloat(partInfo.PartPrice || 0); // Or NonOEM if selected
|
||||
} else if (jobLineType === "SUBLET") {
|
||||
jobLine.part_type = "SUB"; // Custom code for sublet
|
||||
jobLine.part_qty = 1; // Default
|
||||
jobLine.act_price = parseFloat(subletInfo.SubletAmount || 0);
|
||||
jobLine.sublet_vendor = subletInfo.SubletVendorName || null;
|
||||
jobLine.lbr_hrs = parseFloat(subletInfo.SubletLaborHours || 0);
|
||||
} // Labor-only already handled
|
||||
|
||||
jobLine.mod_lbr_ty = laborInfo.LaborType || null;
|
||||
jobLine.mod_lb_hrs = parseFloat(laborInfo.LaborHours || 0);
|
||||
jobLine.lbr_op = laborInfo.LaborOperation || null;
|
||||
jobLine.lbr_amt = parseFloat(laborInfo.LaborAmt || 0);
|
||||
jobLine.notes = line.LineMemo || null;
|
||||
jobLine.manual_line = line.ManualLineInd || null;
|
||||
|
||||
return jobLine;
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const bodyParser = require("body-parser");
|
||||
|
||||
// Pull secrets from env
|
||||
const { VSSTA_INTEGRATION_SECRET, PARTS_MANAGEMENT_INTEGRATION_SECRET } = process.env;
|
||||
@@ -29,7 +28,7 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
|
||||
*/
|
||||
router.post(
|
||||
"/parts-management/VehicleDamageEstimateAddRq",
|
||||
bodyParser.raw({ type: "application/xml", limit: XML_BODY_LIMIT }), // Parse XML body
|
||||
express.raw({ type: "application/xml", limit: XML_BODY_LIMIT }), // Parse XML body
|
||||
partsManagementIntegrationMiddleware,
|
||||
partsManagementVehicleDamageEstimateAddRq
|
||||
);
|
||||
@@ -39,7 +38,7 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
|
||||
*/
|
||||
router.post(
|
||||
"/parts-management/VehicleDamageEstimateChqRq",
|
||||
bodyParser.raw({ type: "application/xml", limit: XML_BODY_LIMIT }), // Parse XML body
|
||||
express.raw({ type: "application/xml", limit: XML_BODY_LIMIT }), // Parse XML body
|
||||
partsManagementIntegrationMiddleware,
|
||||
partsManagementVehicleDamageEstimateChqRq
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user