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

@@ -119,9 +119,8 @@ async function rrMultiCustomerSearch({ bodyshop, job, socket, redisHelpers }) {
try {
CreateRRLogEvent(socket, "DEBUG", `{RR-SEARCH} Executing ${q.kind} query`, { q });
const res = await rrCombinedSearch(bodyshop, q);
if (fromVin) {
const blocks = Array.isArray(res?.data) ? res.data : [];
const blocks = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : [];
ownersSet = ownersFromVinBlocks(blocks, job?.v_vin);
try {
await redisHelpers.setSessionTransactionData(
@@ -132,7 +131,7 @@ async function rrMultiCustomerSearch({ bodyshop, job, socket, redisHelpers }) {
defaultRRTTL
);
} catch {
//
/* ignore cache write issues */
}
}
@@ -159,17 +158,19 @@ function registerRREvents({ socket, redisHelpers }) {
let ownersSet = null;
if ((params?.kind || "").toLowerCase() === "vin") {
const blocks = Array.isArray(res?.data) ? res.data : [];
const blocks = Array.isArray(res?.data) ? res.data : Array.isArray(res) ? res : [];
ownersSet = ownersFromVinBlocks(blocks);
}
const normalized = sortVehicleOwnerFirst(normalizeCustomerCandidates(res, { ownersSet }));
const rid = resolveJobId(jobid, { jobid }, null);
cb?.({ jobid: rid, data: normalized });
socket.emit("rr-select-customer", normalized);
const decorated = normalized.map((c) => (c.vinOwner != null ? c : { ...c, vinOwner: !!c.isVehicleOwner }));
cb?.({ jobid: rid, data: decorated });
socket.emit("rr-select-customer", decorated);
CreateRRLogEvent(socket, "DEBUG", "rr-lookup-combined: emitted rr-select-customer", {
count: normalized.length
count: decorated.length
});
} catch (e) {
CreateRRLogEvent(socket, "ERROR", "RR combined lookup error", { error: e.message, jobid });
@@ -318,10 +319,11 @@ function registerRREvents({ socket, redisHelpers }) {
CreateRRLogEvent(socket, "DEBUG", `{2} Running multi-search (Full Name + VIN)`);
const candidates = await rrMultiCustomerSearch({ bodyshop, job, socket, redisHelpers });
socket.emit("rr-select-customer", candidates);
const decorated = candidates.map((c) => (c.vinOwner != null ? c : { ...c, vinOwner: !!c.isVehicleOwner }));
socket.emit("rr-select-customer", decorated);
CreateRRLogEvent(socket, "DEBUG", `{2.1} Emitted rr-select-customer`, {
count: candidates.length,
anyOwner: candidates.some((c) => c.isVehicleOwner)
count: decorated.length,
anyOwner: decorated.some((c) => c.vinOwner || c.isVehicleOwner)
});
} catch (error) {
CreateRRLogEvent(socket, "ERROR", `Error during RR export (prepare)`, {
@@ -376,7 +378,7 @@ function registerRREvents({ socket, redisHelpers }) {
const vehQ = makeVehicleSearchPayloadFromJob(job);
if (vehQ && vehQ.kind === "vin" && job?.v_vin) {
const resVin = await rrCombinedSearch(bodyshop, vehQ);
const blocksVin = Array.isArray(resVin?.data) ? resVin.data : [];
const blocksVin = Array.isArray(resVin?.data) ? resVin.data : Array.isArray(resVin) ? resVin : [];
try {
await redisHelpers.setSessionTransactionData(
socket.id,