feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -VIN Ownership checks

This commit is contained in:
Dave
2025-11-07 14:36:57 -05:00
parent 9ce022b5e8
commit 5a8a5bf7ab
3 changed files with 114 additions and 34 deletions

View File

@@ -46,6 +46,7 @@ const makeVehicleSearchPayloadFromJob = (job) => {
/**
* Normalize customer candidates from VIN blocks
* Adds `vinOwner` (and keeps `isVehicleOwner` for backward compat).
* @param res
* @param ownersSet
* @returns {any[]}
@@ -66,19 +67,27 @@ const normalizeCustomerCandidates = (res, { ownersSet = null } = {}) => {
for (const custNo of custNos) {
const cno = String(custNo).trim();
const item = { custNo: cno, name: name || `Customer ${cno}` };
if (ownersSet && ownersSet.has(cno)) item.isVehicleOwner = true;
const isOwner = !!(ownersSet && ownersSet.has(cno));
const item = {
custNo: cno,
name: name || `Customer ${cno}`,
vinOwner: isOwner,
isVehicleOwner: isOwner // legacy key kept for any older FE code
};
out.push(item);
}
}
// Dedup by custNo, keep isVehicleOwner if any
// Dedup by custNo, keep vinOwner/isVehicleOwner if any
const seen = new Map();
for (const c of out) {
const key = (c.custNo || "").trim();
if (!key) continue;
const prev = seen.get(key);
if (!prev) seen.set(key, c);
else if (c.isVehicleOwner && !prev.isVehicleOwner) seen.set(key, { ...prev, isVehicleOwner: true });
if (!prev) {
seen.set(key, c);
} else if ((c.vinOwner || c.isVehicleOwner) && !(prev.vinOwner || prev.isVehicleOwner)) {
seen.set(key, { ...prev, vinOwner: true, isVehicleOwner: true });
}
}
return Array.from(seen.values());
};