feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration - Checking in verified
This commit is contained in:
@@ -126,15 +126,6 @@ const digitsOnly = (s) => {
|
|||||||
return String(s || "").replace(/\D/g, "");
|
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.
|
* Build RR customer payload from job.ownr_* fields, with optional overrides.
|
||||||
* @param job
|
* @param job
|
||||||
@@ -155,11 +146,15 @@ const buildCustomerPayloadFromJob = (job, overrides = {}) => {
|
|||||||
const emails = email ? [{ address: String(email) }] : undefined;
|
const emails = email ? [{ address: String(email) }] : undefined;
|
||||||
|
|
||||||
// Phones
|
// Phones
|
||||||
const phoneCandidates = [overrides.phone, job?.ownr_ph1, job?.ownr_ph2]
|
const phone1 = digitsOnly(job?.ownr_ph1);
|
||||||
.map((v) => digitsOnly(v))
|
const phone2 = digitsOnly(job?.ownr_ph2);
|
||||||
.filter((v) => v && v.length >= 7);
|
|
||||||
|
|
||||||
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)
|
// Address (include only if line1 exists; template requires Addr1 if address is present)
|
||||||
const line1 = overrides.addressLine1 ?? job?.ownr_addr1 ?? undefined;
|
const line1 = overrides.addressLine1 ?? job?.ownr_addr1 ?? undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user