From 43dc760c9528cf77783dddd314a53de8523fefef Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 17 Nov 2025 15:01:38 -0500 Subject: [PATCH] feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checking in verified --- server/rr/rr-customers.js | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/server/rr/rr-customers.js b/server/rr/rr-customers.js index 09940f2f3..0895bf5b4 100644 --- a/server/rr/rr-customers.js +++ b/server/rr/rr-customers.js @@ -126,15 +126,6 @@ const digitsOnly = (s) => { return String(s || "").replace(/\D/g, ""); }; -/** - * Return a new array with only unique values from the input array - * @param arr - * @returns {any[]} - */ -const uniq = (arr) => { - return Array.from(new Set(arr)); -}; - /** * Build RR customer payload from job.ownr_* fields, with optional overrides. * @param job @@ -155,11 +146,15 @@ const buildCustomerPayloadFromJob = (job, overrides = {}) => { const emails = email ? [{ address: String(email) }] : undefined; // Phones - const phoneCandidates = [overrides.phone, job?.ownr_ph1, job?.ownr_ph2] - .map((v) => digitsOnly(v)) - .filter((v) => v && v.length >= 7); + const phone1 = digitsOnly(job?.ownr_ph1); + const phone2 = digitsOnly(job?.ownr_ph2); - const phones = uniq(phoneCandidates).map((num) => ({ number: num })); + let primaryPhone = phone1 || phone2; + if (primaryPhone) { + primaryPhone = primaryPhone.slice(-10); // enforce 10 digits + } + + const phones = primaryPhone ? [{ number: primaryPhone, type: "H" }] : []; // Address (include only if line1 exists; template requires Addr1 if address is present) const line1 = overrides.addressLine1 ?? job?.ownr_addr1 ?? undefined;