feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration -VIN Ownership checks
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user