feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration / RRScratch2 / Checkpoint
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
const { buildClientAndOpts, rrCombinedSearch } = require("./rr-lookup");
|
||||
const CreateRRLogEvent = require("./rr-logger-event");
|
||||
|
||||
/**
|
||||
* Pick and normalize VIN from inputs
|
||||
* @param vin
|
||||
@@ -29,6 +28,20 @@ const pickCustNo = ({ selectedCustomerNo, custNo, customerNo }) => {
|
||||
return c != null ? String(c).trim() : "";
|
||||
};
|
||||
|
||||
/**
|
||||
* Simple length sanitizer for outbound strings
|
||||
* Returns undefined if value is null/undefined/empty after trim.
|
||||
*/
|
||||
const sanitizeLength = (value, maxLen) => {
|
||||
if (value == null) return undefined;
|
||||
let s = String(value).trim();
|
||||
if (!s) return undefined;
|
||||
if (maxLen && s.length > maxLen) {
|
||||
s = s.slice(0, maxLen);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extract owner customer numbers from combined search results
|
||||
* @param res
|
||||
@@ -181,41 +194,52 @@ const ensureRRServiceVehicle = async (args = {}) => {
|
||||
}
|
||||
} catch (e) {
|
||||
// Preflight shouldn't be fatal; log and continue to insert (idempotency will still be handled)
|
||||
CreateRRLogEvent(socket, "WARN", "{SV} VIN preflight lookup failed; continuing to insert", {
|
||||
CreateRRLogEvent(socket, "warn", "{SV} VIN preflight lookup failed; continuing to insert", {
|
||||
vin: vinStr,
|
||||
error: e?.message
|
||||
});
|
||||
}
|
||||
|
||||
// Vendor says: MODEL DESCRIPTION HAS MAXIMUM LENGTH OF 20
|
||||
const rawModelDesc = job?.v_model_desc;
|
||||
const safeModelDesc = sanitizeLength(rawModelDesc, 20);
|
||||
if (rawModelDesc && safeModelDesc && rawModelDesc.trim() !== safeModelDesc) {
|
||||
CreateRRLogEvent(socket, "warn", "{SV} Truncated model description to 20 chars", {
|
||||
original: rawModelDesc,
|
||||
truncated: safeModelDesc
|
||||
});
|
||||
}
|
||||
|
||||
const insertPayload = {
|
||||
vin: vinStr.toUpperCase(), // "1FDWX34Y28EB01395"
|
||||
|
||||
// 2-character make code (from v_make_desc → known mapping)
|
||||
vehicleMake: deriveMakeCode(job.v_make_desc), // → "FR" for Ford
|
||||
vehicleMake: deriveMakeCode(job?.v_make_desc), // → "FR" for Ford
|
||||
year: job?.v_model_yr || undefined,
|
||||
// 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
|
||||
|
||||
// Model description (RR: max length 20)
|
||||
modelDesc: safeModelDesc,
|
||||
|
||||
// Model number / carline / other optional fields
|
||||
mdlNo: undefined,
|
||||
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"
|
||||
carline: undefined,
|
||||
extClrDesc: sanitizeLength(job?.v_color, 30), // safe, configurable if vendor complains
|
||||
accentClr: undefined,
|
||||
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
|
||||
aircond: undefined,
|
||||
pwrstr: undefined,
|
||||
transm: undefined,
|
||||
turbo: undefined,
|
||||
engineConfig: undefined,
|
||||
trim: undefined,
|
||||
|
||||
// License plate
|
||||
licNo: license ? String(license).trim() : undefined,
|
||||
licNo: sanitizeLength(license ? String(license) : undefined, 20),
|
||||
|
||||
customerNo: custNoStr,
|
||||
stockId: job.ro_number || undefined, // Use RO as stock# — common pattern
|
||||
stockId: sanitizeLength(job?.ro_number, 20), // RO as stock#, truncated for safety
|
||||
vehicleServInfo: {
|
||||
customerNo: custNoStr, // REQUIRED — this is what toServiceVehicleView() validates
|
||||
salesmanNo: undefined, // You don't have advisor yet — omit
|
||||
salesmanNo: undefined,
|
||||
inServiceDate: undefined,
|
||||
productionDate: undefined,
|
||||
modelMaintCode: undefined,
|
||||
|
||||
Reference in New Issue
Block a user