This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/beacons/list.cfm
John Mizerek be29352b21 Migrate beacon APIs to shard-only system
- save.cfm: Auto-allocates shard+Major to business, creates ServicePoint with Minor
- list.cfm: Lists ServicePoints with BeaconMinor (removed legacy Beacons table)
- list_all.cfm: Returns shard UUIDs instead of legacy beacon UUIDs
- lookup.cfm: Removed legacy UUID lookup, shard-only resolution

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-14 19:33:49 -08:00

120 lines
3.4 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfheader name="Cache-Control" value="no-store">
<cfscript>
function apiAbort(obj) {
writeOutput(serializeJSON(obj));
abort;
}
// Read JSON body once
data = {};
try {
raw = toString(getHttpRequestData().content);
if (len(trim(raw))) {
data = deserializeJSON(raw);
if (!isStruct(data)) data = {};
}
} catch (any e) {
data = {};
}
httpHeaders = getHttpRequestData().headers;
// Get BusinessID from: session > body > X-Business-ID header > URL
bizId = 0;
if (structKeyExists(request, "BusinessID") && isNumeric(request.BusinessID) && request.BusinessID GT 0) {
bizId = int(request.BusinessID);
}
if (bizId LTE 0 && structKeyExists(data, "BusinessID") && isNumeric(data.BusinessID) && data.BusinessID GT 0) {
bizId = int(data.BusinessID);
}
if (bizId LTE 0 && structKeyExists(httpHeaders, "X-Business-ID") && isNumeric(httpHeaders["X-Business-ID"]) && httpHeaders["X-Business-ID"] GT 0) {
bizId = int(httpHeaders["X-Business-ID"]);
}
if (bizId LTE 0 && structKeyExists(url, "BusinessID") && isNumeric(url.BusinessID) && url.BusinessID GT 0) {
bizId = int(url.BusinessID);
}
if (bizId LTE 0) {
apiAbort({ OK=false, ERROR="no_business_selected" });
}
// Default behavior: only active unless onlyActive is explicitly false/0
onlyActive = true;
if (structKeyExists(data, "onlyActive")) {
if (isBoolean(data.onlyActive)) {
onlyActive = data.onlyActive;
} else if (isNumeric(data.onlyActive)) {
onlyActive = (int(data.onlyActive) EQ 1);
} else if (isSimpleValue(data.onlyActive)) {
onlyActive = (lcase(trim(toString(data.onlyActive))) EQ "true");
}
}
</cfscript>
<!--- Get business shard info --->
<cfquery name="qBiz" datasource="payfrit">
SELECT b.ID, b.Name, b.BeaconShardID, b.BeaconMajor, bs.UUID AS ShardUUID
FROM Businesses b
LEFT JOIN BeaconShards bs ON bs.ID = b.BeaconShardID
WHERE b.ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
LIMIT 1
</cfquery>
<cfif qBiz.recordCount EQ 0>
<cfoutput>#serializeJSON({ OK=false, ERROR="business_not_found" })#</cfoutput>
<cfabort>
</cfif>
<cfset hasShard = val(qBiz.BeaconShardID) GT 0>
<cfset shardInfo = {
"ShardID" = hasShard ? qBiz.BeaconShardID : 0,
"ShardUUID" = hasShard ? qBiz.ShardUUID : "",
"Major" = hasShard ? qBiz.BeaconMajor : 0
}>
<!--- Get service points with beacon minor assignments --->
<cfquery name="qSP" datasource="payfrit">
SELECT
sp.ID AS ServicePointID,
sp.Name,
sp.BeaconMinor,
sp.IsActive,
sp.TypeID
FROM ServicePoints sp
WHERE sp.BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
AND sp.BeaconMinor IS NOT NULL
<cfif onlyActive>
AND sp.IsActive = 1
</cfif>
ORDER BY sp.BeaconMinor, sp.Name
</cfquery>
<cfset beacons = []>
<cfloop query="qSP">
<cfset arrayAppend(beacons, {
"ServicePointID" = qSP.ServicePointID,
"BusinessID" = bizId,
"Name" = qSP.Name,
"UUID" = shardInfo.ShardUUID,
"Major" = shardInfo.Major,
"Minor" = qSP.BeaconMinor,
"IsActive" = qSP.IsActive ? true : false,
"TypeID" = qSP.TypeID
})>
</cfloop>
<cfscript>try{logPerf(0);}catch(any e){}</cfscript>
<cfoutput>#serializeJSON({
OK = true,
ERROR = "",
BusinessID = bizId,
BusinessName = qBiz.Name,
COUNT = arrayLen(beacons),
BEACONS = beacons,
HAS_SHARD = hasShard,
SHARD_INFO = shardInfo
})#</cfoutput>