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 client = require("../../../graphql-client/graphql-client").client;
|
||||||
const { parseXml, normalizeXmlObject } = require("../partsManagementUtils");
|
const { parseXml, normalizeXmlObject } = require("../partsManagementUtils");
|
||||||
|
const { toArray } = require("lodash");
|
||||||
|
|
||||||
// GraphQL Queries and Mutations
|
// GraphQL Queries and Mutations
|
||||||
const {
|
const {
|
||||||
@@ -373,37 +374,48 @@ const extractVehicleData = (rq, shopId) => {
|
|||||||
* @returns {object[]} Array of job line objects.
|
* @returns {object[]} Array of job line objects.
|
||||||
*/
|
*/
|
||||||
const extractJobLines = (rq) => {
|
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) => {
|
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 = {
|
const jobLine = {
|
||||||
line_no: parseInt(line.LineNum, 10),
|
line_no: parseInt(line.LineNum || 0, 10),
|
||||||
unq_seq: parseInt(line.UniqueSequenceNum, 10),
|
unq_seq: parseInt(line.UniqueSequenceNum || 0, 10),
|
||||||
status: line.LineStatusCode || null,
|
status: line.LineStatusCode || null,
|
||||||
line_desc: line.LineDesc || null,
|
line_desc: line.LineDesc || null
|
||||||
part_type: line.PartInfo?.PartType || null,
|
// line_type: jobLineType // New field for clarity
|
||||||
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
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Commented out as not clear if needed for version 1, this only applies to Imex and not rome on the front
|
if (jobLineType === "PART") {
|
||||||
// end
|
jobLine.part_type = partInfo.PartType || null;
|
||||||
// if ((jobLine.part_type === "PASL" || jobLine.part_type === "PAS") && jobLine.lbr_op !== "OP11") {
|
jobLine.part_qty = parseFloat(partInfo.Quantity || 0);
|
||||||
// jobLine.tax_part = true;
|
jobLine.oem_partno = partInfo.OEMPartNum || null;
|
||||||
// }
|
jobLine.db_price = parseFloat(partInfo.PartPrice || 0);
|
||||||
// if (line.db_ref === "900510") {
|
jobLine.act_price = parseFloat(partInfo.PartPrice || 0); // Or NonOEM if selected
|
||||||
// jobLine.tax_part = true;
|
} 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;
|
return jobLine;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
const express = require("express");
|
const express = require("express");
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const bodyParser = require("body-parser");
|
|
||||||
|
|
||||||
// Pull secrets from env
|
// Pull secrets from env
|
||||||
const { VSSTA_INTEGRATION_SECRET, PARTS_MANAGEMENT_INTEGRATION_SECRET } = process.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(
|
router.post(
|
||||||
"/parts-management/VehicleDamageEstimateAddRq",
|
"/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,
|
partsManagementIntegrationMiddleware,
|
||||||
partsManagementVehicleDamageEstimateAddRq
|
partsManagementVehicleDamageEstimateAddRq
|
||||||
);
|
);
|
||||||
@@ -39,7 +38,7 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
|
|||||||
*/
|
*/
|
||||||
router.post(
|
router.post(
|
||||||
"/parts-management/VehicleDamageEstimateChqRq",
|
"/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,
|
partsManagementIntegrationMiddleware,
|
||||||
partsManagementVehicleDamageEstimateChqRq
|
partsManagementVehicleDamageEstimateChqRq
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user