feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint

This commit is contained in:
Dave
2025-11-05 12:04:14 -05:00
parent da28fe8592
commit 9341806b0f
5 changed files with 49 additions and 51 deletions

View File

@@ -1,6 +1,3 @@
// server/rr/rr-job-helpers.js
// Utilities to fetch and map job data into RR payloads using the shared Hasura client.
const client = require("../graphql-client/graphql-client").client;
const { GET_JOB_BY_PK } = require("../graphql-client/queries");
@@ -52,33 +49,28 @@ async function QueryJobData(ctx = {}, jobId) {
}
}
/**
* Build minimal RR RO payload (keys match your RR clients expectations).
* Uses fields that exist in your schema (v_vin, ro_number, owner fields, etc).
*/
/**
* Build minimal RR RO payload (keys match RR client expectations).
* - Requires advisorNo (maps to advNo)
* - Uses custNo (normalized) and a cleaned VIN (17 chars, AZ/09)
* - Requires advisor number and customer number.
* - We provide BOTH "customerNo" and "custNo" (and BOTH "advisorNo" and "advNo")
* to be compatible with the compiled RR CJS lib which currently requires
* "customerNo (or CustNo)".
*/
function buildRRRepairOrderPayload({ job, selectedCustomer, advisorNo }) {
// Resolve custNo from object or primitive
const custNoRaw =
(selectedCustomer &&
(selectedCustomer.custNo ||
selectedCustomer.customerNo || // legacy alias, normalized below
selectedCustomer.CustNo)) ||
(typeof selectedCustomer === "string" || typeof selectedCustomer === "number" ? String(selectedCustomer) : null);
// Resolve customerNo from object or primitive; accept multiple incoming shapes
const custNo = custNoRaw ? String(custNoRaw).trim() : null;
if (!custNo) throw new Error("No RR customer selected (custNo missing)");
const customerNo = selectedCustomer?.customerNo ? String(selectedCustomer?.customerNo).trim() : null;
// Advisor is required for RR
const advNo = advisorNo != null && String(advisorNo).trim() !== "" ? String(advisorNo).trim() : null;
if (!advNo) throw new Error("advisorNo is required for RR export");
if (!customerNo) throw new Error("No RR customer selected (customerNo/CustNo missing)");
// Advisor number (accepts advisorNo string, map to both keys)
const adv = advisorNo != null && String(advisorNo).trim() !== "" ? String(advisorNo).trim() : null;
if (!adv) throw new Error("advisorNo is required for RR export");
// Clean/normalize VIN if present
const vinRaw = job?.v_vin || job?.vehicle?.vin || job?.vin;
const vinRaw = job?.v_vin;
const vin =
typeof vinRaw === "string"
? vinRaw
@@ -88,17 +80,17 @@ function buildRRRepairOrderPayload({ job, selectedCustomer, advisorNo }) {
: undefined;
// Pick a stable external RO number
const ro =
job?.ro_number != null ? job.ro_number : job?.job_number != null ? job.job_number : job?.id != null ? job.id : null;
const ro = job?.ro_number != null ? job.ro_number : job?.id != null ? job.id : null;
if (ro == null) throw new Error("Missing repair order identifier (ro_number/job_number/id).");
if (ro == null) throw new Error("Missing repair order identifier (ro_number/job_number/id)");
// Provide superset of keys for maximum compatibility with the RR client
return {
repairOrderNumber: String(ro),
deptType: "B",
vin, // undefined if absent/empty after cleaning
custNo: String(custNo),
advNo // mapped from advisorNo
vin,
customerNo: String(customerNo),
advisorNo: adv
};
}
@@ -170,6 +162,8 @@ function normalizeCustomerCandidates(res) {
*/
function normalizeVehicleCandidates(res) {
const blocks = blocksFromCombinedSearchResult(res);
console.log("Normalized vehicle Candiadates!!!!!!!!!!!!!!!!!!!!!");
console.dir({ res, blocks }, { depth: null });
const out = [];
for (const blk of blocks) {
const serv = Array.isArray(blk?.ServVehicle) ? blk.ServVehicle : [];