payfrit-works/api/setup/checkDuplicate.cfm
John Mizerek d4e0ae1162 Add branding features: header upload and brand color picker
- Add uploadHeader.cfm API for 1200px header images
- Add saveBrandColor.cfm API for hex color storage
- Add Branding section to menu builder sidebar
- Fix header upload path and permissions
- Various beacon and service point API improvements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-18 12:14:24 -08:00

92 lines
3 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
/**
* Check for duplicate businesses
*
* POST JSON:
* {
* "name": "Business Name",
* "addressLine1": "123 Main St",
* "city": "Los Angeles",
* "state": "CA",
* "zip": "90001"
* }
*
* Returns:
* {
* "OK": true,
* "duplicates": [ { BusinessID, BusinessName, Address } ]
* }
*/
response = { "OK": true, "duplicates": [] };
try {
requestBody = toString(getHttpRequestData().content);
if (!len(requestBody)) {
throw(message="No request body provided");
}
data = deserializeJSON(requestBody);
bizName = structKeyExists(data, "name") && isSimpleValue(data.name) ? trim(data.name) : "";
addressLine1 = structKeyExists(data, "addressLine1") && isSimpleValue(data.addressLine1) ? trim(data.addressLine1) : "";
city = structKeyExists(data, "city") && isSimpleValue(data.city) ? trim(data.city) : "";
state = structKeyExists(data, "state") && isSimpleValue(data.state) ? trim(data.state) : "";
zip = structKeyExists(data, "zip") && isSimpleValue(data.zip) ? trim(data.zip) : "";
// Clean up city - remove trailing punctuation
city = reReplace(city, "[,.\s]+$", "", "all");
// Build query to find potential duplicates
// Match by name (case-insensitive) OR by address components
qDuplicates = queryExecute("
SELECT DISTINCT
b.BusinessID,
b.BusinessName,
a.AddressLine1,
a.AddressCity,
s.tt_StateAbbreviation as AddressState,
a.AddressZIPCode
FROM Businesses b
LEFT JOIN Addresses a ON a.AddressBusinessID = b.BusinessID
LEFT JOIN tt_States s ON s.tt_StateID = a.AddressStateID
WHERE
LOWER(b.BusinessName) = LOWER(:bizName)
OR (
LOWER(a.AddressLine1) = LOWER(:addressLine1)
AND LOWER(a.AddressCity) = LOWER(:city)
AND a.AddressLine1 != ''
AND a.AddressCity != ''
)
ORDER BY b.BusinessName
", {
bizName: bizName,
addressLine1: addressLine1,
city: city
}, { datasource: "payfrit" });
for (i = 1; i <= qDuplicates.recordCount; i++) {
addressParts = [];
if (len(qDuplicates.AddressLine1[i])) arrayAppend(addressParts, qDuplicates.AddressLine1[i]);
if (len(qDuplicates.AddressCity[i])) arrayAppend(addressParts, qDuplicates.AddressCity[i]);
if (len(qDuplicates.AddressState[i])) arrayAppend(addressParts, qDuplicates.AddressState[i]);
if (len(qDuplicates.AddressZIPCode[i])) arrayAppend(addressParts, qDuplicates.AddressZIPCode[i]);
arrayAppend(response.duplicates, {
"BusinessID": qDuplicates.BusinessID[i],
"BusinessName": qDuplicates.BusinessName[i],
"Address": arrayToList(addressParts, ", ")
});
}
} catch (any e) {
response.OK = false;
response.error = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>