feature/IO-3255-simplified-parts-management - Checkpoint
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
// no-dd-sa:javascript-code-style/assignment-name
|
// no-dd-sa:javascript-code-style/assignment-name
|
||||||
// The above disables camel case inspection for the file,
|
// CamelCase is used for GraphQL and database fields.
|
||||||
// CamelCase is used for GraphQL and database fields, and it is easier
|
|
||||||
// to maintain consistency with the existing codebase.
|
|
||||||
|
|
||||||
const xml2js = require("xml2js");
|
const xml2js = require("xml2js");
|
||||||
const client = require("../../graphql-client/graphql-client").client;
|
const client = require("../../graphql-client/graphql-client").client;
|
||||||
@@ -30,7 +28,6 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
logger.log("parts-xml-parse", "debug", null, null, { success: true });
|
logger.log("parts-xml-parse", "debug", null, null, { success: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.log("parts-xml-parse-error", "error", null, null, { error: err });
|
logger.log("parts-xml-parse-error", "error", null, null, { error: err });
|
||||||
console.dir(err);
|
|
||||||
return res.status(400).send("Invalid XML");
|
return res.status(400).send("Invalid XML");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,23 +38,22 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ── SHOP ID ────────────────────────────────────────────────────────────────
|
// ── SHOP & CLAIM IDs ────────────────────────────────────────────────────────
|
||||||
const shopId = rq.ShopID || rq.shopId;
|
const shopId = rq.ShopID || rq.shopId;
|
||||||
if (!shopId) {
|
if (!shopId) throw { status: 400, message: "Missing <ShopID> in XML" };
|
||||||
throw { status: 400, message: "Missing <ShopID> in XML" };
|
const { RefClaimNum } = rq;
|
||||||
}
|
|
||||||
|
|
||||||
// ── DOCUMENT INFO ──────────────────────────────────────────────────────────
|
// ── DOCUMENT INFO ──────────────────────────────────────────────────────────
|
||||||
const { RefClaimNum } = rq;
|
|
||||||
const doc = rq.DocumentInfo || {};
|
const doc = rq.DocumentInfo || {};
|
||||||
const comment = doc.Comment || null;
|
const comment = doc.Comment || null;
|
||||||
const date_exported = doc.TransmitDateTime || null;
|
const date_exported = doc.TransmitDateTime || null;
|
||||||
|
// capture CIECA ID & totals
|
||||||
const docVers = doc.DocumentVer ? (Array.isArray(doc.DocumentVer) ? doc.DocumentVer : [doc.DocumentVer]) : [];
|
const ciecaid = rq.RqUID || null;
|
||||||
const documentVersions = docVers.map((dv) => ({
|
const cieca_ttl = parseFloat(rq.Cieca_ttl || 0);
|
||||||
code: dv.DocumentVerCode,
|
// map DocumentInfo fields to our category/class fields
|
||||||
num: dv.DocumentVerNum
|
const cat_no = doc.VendorCode || null;
|
||||||
}));
|
const category = doc.DocumentType || null;
|
||||||
|
const classType = doc.DocumentStatus || null;
|
||||||
|
|
||||||
// ── EVENT INFO ──────────────────────────────────────────────────────────────
|
// ── EVENT INFO ──────────────────────────────────────────────────────────────
|
||||||
const ev = rq.EventInfo || {};
|
const ev = rq.EventInfo || {};
|
||||||
@@ -65,18 +61,17 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
const asgn_no = asgn.AssignmentNumber || null;
|
const asgn_no = asgn.AssignmentNumber || null;
|
||||||
const asgn_type = asgn.AssignmentType || null;
|
const asgn_type = asgn.AssignmentType || null;
|
||||||
const asgn_date = asgn.AssignmentDate || null;
|
const asgn_date = asgn.AssignmentDate || null;
|
||||||
const scheduled_completion = ev.RepairEvent?.TargetCompletionDateTime || null;
|
|
||||||
const scheduled_in = ev.RepairEvent?.RequestedPickUpDateTime || null;
|
const scheduled_in = ev.RepairEvent?.RequestedPickUpDateTime || null;
|
||||||
|
const scheduled_completion = ev.RepairEvent?.TargetCompletionDateTime || null;
|
||||||
|
|
||||||
// ── CLAIM INFO ──────────────────────────────────────────────────────────────
|
// ── CLAIM & POLICY ──────────────────────────────────────────────────────────
|
||||||
const ci = rq.ClaimInfo || {};
|
const ci = rq.ClaimInfo || {};
|
||||||
const clm_no = ci.ClaimNum || null;
|
const clm_no = ci.ClaimNum || null;
|
||||||
const status = ci.ClaimStatus || null;
|
const status = ci.ClaimStatus || null;
|
||||||
const policy_no = ci.PolicyInfo?.PolicyNum || null;
|
const policy_no = ci.PolicyInfo?.PolicyNum || null;
|
||||||
const ded_amt = parseFloat(ci.PolicyInfo?.CoverageInfo?.Coverage?.DeductibleInfo?.DeductibleAmt || 0);
|
const ded_amt = parseFloat(ci.PolicyInfo?.CoverageInfo?.Coverage?.DeductibleInfo?.DeductibleAmt || 0);
|
||||||
const clm_total = parseFloat(ci.Cieca_ttl || 0);
|
|
||||||
|
|
||||||
// ── ADMIN / OWNER INFO ──────────────────────────────────────────────────────
|
// ── OWNER ────────────────────────────────────────────────────────────────────
|
||||||
const ownerParty = rq.AdminInfo?.Owner?.Party || {};
|
const ownerParty = rq.AdminInfo?.Owner?.Party || {};
|
||||||
const ownr_fn = ownerParty.PersonInfo?.PersonName?.FirstName || null;
|
const ownr_fn = ownerParty.PersonInfo?.PersonName?.FirstName || null;
|
||||||
const ownr_ln = ownerParty.PersonInfo?.PersonName?.LastName || null;
|
const ownr_ln = ownerParty.PersonInfo?.PersonName?.LastName || null;
|
||||||
@@ -88,30 +83,89 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
const ownr_st = adr.StateProvince || null;
|
const ownr_st = adr.StateProvince || null;
|
||||||
const ownr_zip = adr.PostalCode || null;
|
const ownr_zip = adr.PostalCode || null;
|
||||||
const ownr_ctry = adr.Country || null;
|
const ownr_ctry = adr.Country || null;
|
||||||
|
let ownr_ph1;
|
||||||
const ownrComms = ownerParty.ContactInfo?.Communications
|
let ownr_ph2;
|
||||||
? Array.isArray(ownerParty.ContactInfo.Communications)
|
let ownr_fax;
|
||||||
? ownerParty.ContactInfo.Communications
|
let ownr_ea;
|
||||||
: [ownerParty.ContactInfo.Communications]
|
(Array.isArray(ownerParty.ContactInfo?.Communications)
|
||||||
: [];
|
? ownerParty.ContactInfo.Communications
|
||||||
let ownr_ph1 = null,
|
: [ownerParty.ContactInfo?.Communications || {}]
|
||||||
ownr_ph2 = null,
|
).forEach((c) => {
|
||||||
ownr_fax = null,
|
|
||||||
ownr_ea = null;
|
|
||||||
ownrComms.forEach((c) => {
|
|
||||||
if (c.CommQualifier === "CP") ownr_ph1 = c.CommPhone;
|
if (c.CommQualifier === "CP") ownr_ph1 = c.CommPhone;
|
||||||
if (c.CommQualifier === "WP") ownr_ph2 = c.CommPhone;
|
if (c.CommQualifier === "WP") ownr_ph2 = c.CommPhone;
|
||||||
if (c.CommQualifier === "FX") ownr_fax = c.CommPhone;
|
if (c.CommQualifier === "FX") ownr_fax = c.CommPhone;
|
||||||
if (c.CommQualifier === "EM") ownr_ea = c.CommEmail;
|
if (c.CommQualifier === "EM") ownr_ea = c.CommEmail;
|
||||||
});
|
});
|
||||||
const preferred_contact = ownerParty.PreferredContactMethod || null;
|
|
||||||
|
|
||||||
// ── VEHICLE INFO (nested relationship) ──────────────────────────────────────
|
// Estimator → map to est_… fields
|
||||||
|
const estParty = rq.AdminInfo?.Estimator?.Party || {};
|
||||||
|
// grab raw first/last
|
||||||
|
const est_fn = estParty.PersonInfo?.PersonName?.FirstName || null;
|
||||||
|
const est_ln = estParty.PersonInfo?.PersonName?.LastName || null;
|
||||||
|
// now alias into the GraphQL names
|
||||||
|
const est_ct_fn = est_fn;
|
||||||
|
const est_ct_ln = est_ln;
|
||||||
|
|
||||||
|
const est_aff = rq.AdminInfo?.Estimator?.Affiliation || null;
|
||||||
|
const estComms = Array.isArray(estParty.ContactInfo?.Communications)
|
||||||
|
? estParty.ContactInfo.Communications
|
||||||
|
: [estParty.ContactInfo?.Communications || {}];
|
||||||
|
const est_ea = estComms.find((c) => c.CommQualifier === "EM")?.CommEmail || null;
|
||||||
|
|
||||||
|
// ── ADJUSTER ────────────────────────────────────────────────────────────────
|
||||||
|
const adjParty = rq.AdminInfo?.Adjuster?.Party || {};
|
||||||
|
const agt_ct_fn = adjParty.PersonInfo?.PersonName?.FirstName || null;
|
||||||
|
const agt_ct_ln = adjParty.PersonInfo?.PersonName?.LastName || null;
|
||||||
|
const agt_ct_ph =
|
||||||
|
(Array.isArray(adjParty.ContactInfo?.Communications)
|
||||||
|
? adjParty.ContactInfo.Communications
|
||||||
|
: [adjParty.ContactInfo?.Communications || {}]
|
||||||
|
).find((c) => c.CommQualifier === "CP")?.CommPhone || null;
|
||||||
|
const agt_ea =
|
||||||
|
(Array.isArray(adjParty.ContactInfo?.Communications)
|
||||||
|
? adjParty.ContactInfo.Communications
|
||||||
|
: [adjParty.ContactInfo?.Communications || {}]
|
||||||
|
).find((c) => c.CommQualifier === "EM")?.CommEmail || null;
|
||||||
|
|
||||||
|
// ── REPAIR FACILITY ─────────────────────────────────────────────────────────
|
||||||
|
const rfParty = rq.AdminInfo?.RepairFacility?.Party || {};
|
||||||
|
const servicing_dealer = rfParty.OrgInfo?.CompanyName || null;
|
||||||
|
const servicing_dealer_contact =
|
||||||
|
(Array.isArray(rfParty.ContactInfo?.Communications)
|
||||||
|
? rfParty.ContactInfo.Communications
|
||||||
|
: [rfParty.ContactInfo?.Communications || {}]
|
||||||
|
).find((c) => c.CommQualifier === "WP" || c.CommQualifier === "FX")?.CommPhone || null;
|
||||||
|
|
||||||
|
// ── VEHICLE (one-to-one) ─────────────────────────────────────────────────────
|
||||||
|
const vin = rq.VehicleInfo?.VINInfo?.VINNum || null;
|
||||||
|
const plate_no = rq.VehicleInfo?.License?.LicensePlateNum || null;
|
||||||
|
const plate_st = rq.VehicleInfo?.License?.LicensePlateStateProvince || null;
|
||||||
const desc = rq.VehicleInfo?.VehicleDesc || {};
|
const desc = rq.VehicleInfo?.VehicleDesc || {};
|
||||||
|
const v_model_yr = desc.ModelYear || null;
|
||||||
|
const v_make_desc = desc.MakeDesc || null;
|
||||||
|
const v_model_desc = desc.ModelName || null;
|
||||||
|
const body_style = desc.BodyStyle || null;
|
||||||
|
const engine_desc = desc.EngineDesc || null;
|
||||||
|
const production_date = desc.ProductionDate || null;
|
||||||
|
const v_options = desc.SubModelDesc || null;
|
||||||
|
const v_type = desc.FuelType || null;
|
||||||
|
const v_cond = rq.VehicleInfo?.Condition?.DrivableInd;
|
||||||
|
|
||||||
const vehicleData = {
|
const vehicleData = {
|
||||||
shopid: shopId,
|
shopid: shopId,
|
||||||
plate_no: rq.VehicleInfo?.License?.LicensePlateNum || null,
|
v_vin: vin,
|
||||||
plate_st: rq.VehicleInfo?.License?.LicensePlateStateProvince || null
|
plate_no,
|
||||||
|
plate_st,
|
||||||
|
v_model_yr,
|
||||||
|
v_make_desc,
|
||||||
|
v_model_desc,
|
||||||
|
v_color: rq.VehicleInfo?.Paint?.Exterior?.ColorName || null,
|
||||||
|
v_bstyle: body_style,
|
||||||
|
v_engine: engine_desc,
|
||||||
|
// prod_dt: production_date,
|
||||||
|
v_options,
|
||||||
|
v_type,
|
||||||
|
v_cond
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── DAMAGE LINES → joblinesData ────────────────────────────────────────────
|
// ── DAMAGE LINES → joblinesData ────────────────────────────────────────────
|
||||||
@@ -122,16 +176,12 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
status: line.LineStatusCode || null,
|
status: line.LineStatusCode || null,
|
||||||
line_desc: line.LineDesc || null,
|
line_desc: line.LineDesc || null,
|
||||||
|
|
||||||
// parts (only fields for jobline table)
|
// parts
|
||||||
part_type: line.PartInfo?.PartType || null,
|
part_type: line.PartInfo?.PartType || null,
|
||||||
part_qty: parseInt(line.PartInfo?.Quantity || 0, 10),
|
part_qty: parseFloat(line.PartInfo?.Quantity || 0),
|
||||||
|
oem_partno: line.PartInfo?.OEMPartNum || null,
|
||||||
db_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
db_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||||
act_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
act_price: parseFloat(line.PartInfo?.PartPrice || 0),
|
||||||
oem_partno: line.PartInfo?.OEMPartNum || null,
|
|
||||||
tax_part: line.PartInfo?.TaxableInd === "1",
|
|
||||||
glass_flag: line.PartInfo?.GlassPartInd === "1",
|
|
||||||
price_j: line.PriceJudgmentInd === "1",
|
|
||||||
price_inc: line.PriceInclInd === "1",
|
|
||||||
|
|
||||||
// labor
|
// labor
|
||||||
mod_lbr_ty: line.LaborInfo?.LaborType || null,
|
mod_lbr_ty: line.LaborInfo?.LaborType || null,
|
||||||
@@ -146,19 +196,31 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
const jobInput = {
|
const jobInput = {
|
||||||
shopid: shopId,
|
shopid: shopId,
|
||||||
ro_number: RefClaimNum,
|
ro_number: RefClaimNum,
|
||||||
|
|
||||||
|
// IDs & CIECA metadata
|
||||||
|
ciecaid,
|
||||||
|
cieca_ttl,
|
||||||
|
cat_no,
|
||||||
|
category,
|
||||||
|
class: classType,
|
||||||
|
|
||||||
|
// claim & policy
|
||||||
clm_no,
|
clm_no,
|
||||||
status,
|
status,
|
||||||
clm_total,
|
clm_total: cieca_ttl,
|
||||||
policy_no,
|
policy_no,
|
||||||
ded_amt,
|
ded_amt,
|
||||||
|
|
||||||
|
// document & events
|
||||||
comment,
|
comment,
|
||||||
date_exported,
|
date_exported,
|
||||||
asgn_no,
|
asgn_no,
|
||||||
asgn_type,
|
asgn_type,
|
||||||
asgn_date,
|
asgn_date,
|
||||||
scheduled_completion,
|
|
||||||
scheduled_in,
|
scheduled_in,
|
||||||
|
scheduled_completion,
|
||||||
|
|
||||||
|
// owner
|
||||||
ownr_fn,
|
ownr_fn,
|
||||||
ownr_ln,
|
ownr_ln,
|
||||||
ownr_co_nm,
|
ownr_co_nm,
|
||||||
@@ -172,36 +234,38 @@ const partsManagementVehicleDamageEstimateAddRq = async (req, res) => {
|
|||||||
ownr_ph2,
|
ownr_ph2,
|
||||||
ownr_fax,
|
ownr_fax,
|
||||||
ownr_ea,
|
ownr_ea,
|
||||||
// preferred_contact,
|
|
||||||
|
|
||||||
// nest vehicle & joblines
|
// estimator
|
||||||
vehicle: { data: vehicleData },
|
// est_co_id: est_aff,
|
||||||
joblines: { data: joblinesData },
|
est_ct_fn,
|
||||||
|
est_ct_ln,
|
||||||
|
est_ea,
|
||||||
|
|
||||||
|
// adjuster
|
||||||
|
agt_ct_fn,
|
||||||
|
agt_ct_ln,
|
||||||
|
agt_ct_ph,
|
||||||
|
agt_ea,
|
||||||
|
|
||||||
|
// repair facility
|
||||||
|
servicing_dealer,
|
||||||
|
servicing_dealer_contact,
|
||||||
|
|
||||||
|
// stash any extra CIECA stuff we didn’t map above
|
||||||
production_vars: {
|
production_vars: {
|
||||||
documentVersions
|
documentVersions: [] // we’ve flattened these
|
||||||
}
|
},
|
||||||
|
|
||||||
|
// nested relationships
|
||||||
|
vehicle: { data: vehicleData },
|
||||||
|
joblines: { data: joblinesData }
|
||||||
};
|
};
|
||||||
|
|
||||||
logger.log("parts-insert-job", "debug", null, null, { jobInput });
|
logger.log("parts-insert-job", "debug", null, null, { jobInput });
|
||||||
const { insert_jobs_one: newJob } = await client.request(INSERT_JOB_WITH_LINES, { job: jobInput });
|
const { insert_jobs_one: newJob } = await client.request(INSERT_JOB_WITH_LINES, { job: jobInput });
|
||||||
const jobId = newJob.id;
|
logger.log("parts-job-created", "info", newJob.id, null);
|
||||||
logger.log("parts-job-created", "info", jobId, null);
|
|
||||||
|
|
||||||
/*
|
return res.status(200).json({ success: true, jobId: newJob.id });
|
||||||
// ── PARTS ORDERS ─────────────────────────────────────────────────────────
|
|
||||||
// The integration no longer requires parts_orders,
|
|
||||||
// all related logic is commented out.
|
|
||||||
|
|
||||||
const seqToId = newJob.joblines.reduce((map, ln) => {
|
|
||||||
map[ln.unq_seq] = ln.id;
|
|
||||||
return map;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
// ... grouping logic and mutation calls removed ...
|
|
||||||
*/
|
|
||||||
|
|
||||||
return res.status(200).json({ success: true, jobId });
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.log("parts-route-error", "error", null, null, { error: err });
|
logger.log("parts-route-error", "error", null, null, { error: err });
|
||||||
return res.status(err.status || 500).json({ error: err.message || "Internal error" });
|
return res.status(err.status || 500).json({ error: err.message || "Internal error" });
|
||||||
|
|||||||
Reference in New Issue
Block a user