feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checking in verified

This commit is contained in:
Dave
2025-11-17 15:01:38 -05:00
parent cfd5aaff87
commit 43dc760c95

View File

@@ -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;