feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -Full Flow verified

This commit is contained in:
Dave
2025-11-20 14:52:39 -05:00
parent 34f45379a6
commit c3bc29fa9b
7 changed files with 298 additions and 222 deletions

View File

@@ -64,6 +64,47 @@ const isAlreadyExistsError = (e) => {
return msg.includes("ALREADY EXISTS") || msg.includes("VEHICLE ALREADY EXISTS");
};
function deriveMakeCode(makeDesc) {
if (!makeDesc) return "FR"; // safe default
const map = {
Ford: "FO",
FORD: "FO",
Lincoln: "LN",
Mercury: "MY",
Chevrolet: "CH",
GMC: "GM",
Cadillac: "CA",
Buick: "BU",
Pontiac: "PO",
Oldsmobile: "OL",
Saturn: "SA",
Dodge: "DO",
Chrysler: "CH",
Jeep: "JE",
Plymouth: "PL",
Toyota: "TY",
Lexus: "LX",
Honda: "HO",
Acura: "AC",
Nissan: "NI",
Infiniti: "IN",
Hyundai: "HY",
Kia: "KI",
Subaru: "SU",
Mazda: "MZ",
Volkswagen: "VW",
Audi: "AU",
BMW: "BM",
Mercedes: "MB",
"Mercedes-Benz": "MB",
Volvo: "VO",
Ram: "RA" // post-2010
};
return map[makeDesc.trim().toUpperCase()] || "FR"; // TODO Default set
}
/**
* Ensure/create a Service Vehicle in RR for the given VIN + customer.
* Args may contain:
@@ -150,10 +191,57 @@ const ensureRRServiceVehicle = async (args = {}) => {
// IMPORTANT: The current RR lib build validates `vehicleServInfo.customerNo`.
// To be future-proof, we also include top-level `customerNo`.
const insertPayload = {
vin: vinStr,
customerNo: custNoStr, // fallback form (some builds accept this)
vehicleServInfo: { customerNo: custNoStr }, // primary form expected by the lib
vehicleDetail: license ? { licNo: String(license).trim() } : undefined
// === Core Vehicle Identity (MANDATORY for success) ===
vin: vinStr.toUpperCase(), // "1FDWX34Y28EB01395"
// Required: 2-character make code (from v_make_desc → known mapping)
vehicleMake: deriveMakeCode(job.v_make_desc), // → "FR" for Ford
// Required: 2-digit year (last 2 digits of v_model_yr)
year: job?.v_model_yr || undefined,
// Required: Model number — fallback strategy per ERA behavior
// Most Ford trucks use "T" = Truck. Some systems accept actual code.
// CAN BE (P)assenger , (T)ruck, (O)ther
mdlNo: undefined,
// === Descriptive Fields (highly recommended) ===
modelDesc: job?.v_model_desc?.trim() || undefined, // "F-350 SD"
carline: job?.v_model_desc?.trim() || undefined, // Series line
extClrDesc: job?.v_color?.trim() || undefined, // "Red"
// Optional but helpful
accentClr: undefined,
// === VehicleDetail Flags (CRITICAL — cause silent fails or error 303 if missing) ===
aircond: undefined, // "Y", // Nearly all modern vehicles have A/C
pwrstr: undefined, // "Y", // Power steering = yes on 99% of vehicles post-1990
transm: undefined, // "A", // Default to Automatic — change to "M" only if known manual
turbo: undefined, //"N", // 2008 F-350 6.4L Power Stroke has turbo, but field is optional
engineConfig: undefined, //"V8", // or "6.4L Diesel" — optional but nice
trim: undefined, //"XLT", // You don't have this — safe to omit or guess
// License plate
licNo: license ? String(license).trim() : undefined,
// === VehicleServInfo (attributes on the element) ===
customerNo: custNoStr, // fallback (some builds read this)
stockId: job.ro_number || undefined, // Use RO as stock# — common pattern
vehicleServInfo: {
customerNo: custNoStr, // REQUIRED — this is what toServiceVehicleView() validates
// Optional but increases success rate
salesmanNo: undefined, // You don't have advisor yet — omit
inServiceDate: undefined,
// Optional — safe to include if you want
productionDate: undefined,
modelMaintCode: undefined,
teamCode: undefined,
// Extended warranty — omit unless you sell contracts
vehExtWarranty: undefined,
// Advisor — omit unless you know who the service advisor is
advisor: undefined
}
};
const insertOpts = {