feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checkpoint
This commit is contained in:
@@ -56,21 +56,49 @@ async function QueryJobData(ctx = {}, jobId) {
|
||||
* Build minimal RR RO payload (keys match your RR client’s 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, A–Z/0–9)
|
||||
*/
|
||||
function buildRRRepairOrderPayload({ job, selectedCustomer, advisorNo }) {
|
||||
const custNo =
|
||||
(selectedCustomer && (selectedCustomer.custNo || selectedCustomer.customerNo)) ||
|
||||
// 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);
|
||||
|
||||
const custNo = custNoRaw ? String(custNoRaw).trim() : null;
|
||||
if (!custNo) throw new Error("No RR customer selected (custNo missing)");
|
||||
|
||||
const vin = safeVin(job);
|
||||
// For RR create flows, VIN is typically required; leave null allowed if you gate earlier in your flow.
|
||||
// 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");
|
||||
|
||||
// Clean/normalize VIN if present
|
||||
const vinRaw = job?.v_vin || job?.vehicle?.vin || job?.vin;
|
||||
const vin =
|
||||
typeof vinRaw === "string"
|
||||
? vinRaw
|
||||
.replace(/[^A-Za-z0-9]/g, "")
|
||||
.toUpperCase()
|
||||
.slice(0, 17) || undefined
|
||||
: 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;
|
||||
|
||||
if (ro == null) throw new Error("Missing repair order identifier (ro_number/job_number/id).");
|
||||
|
||||
return {
|
||||
repairOrderNumber: String(job?.ro_number || job?.job_number || job?.id),
|
||||
repairOrderNumber: String(ro),
|
||||
deptType: "B",
|
||||
vin: vin || undefined,
|
||||
custNo,
|
||||
advNo: advisorNo || undefined
|
||||
vin, // undefined if absent/empty after cleaning
|
||||
custNo: String(custNo),
|
||||
advNo // mapped from advisorNo
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user