For businesses using beacon sharding: - beacons/list.cfm now returns ServicePoints with BeaconMinor as beacons - assignments/list.cfm now shows sharding assignments (SP + Minor) - Both APIs include USES_SHARDING flag and sharding info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
156 lines
4.4 KiB
Text
156 lines
4.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 beacons 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>
|
|
|
|
<!--- Check if this business uses beacon sharding --->
|
|
<cfquery name="qBiz" datasource="payfrit">
|
|
SELECT BeaconShardID, BeaconMajor
|
|
FROM Businesses
|
|
WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
|
|
LIMIT 1
|
|
</cfquery>
|
|
|
|
<cfset usesSharding = qBiz.recordCount GT 0 AND val(qBiz.BeaconShardID) GT 0>
|
|
<cfset shardingInfo = {}>
|
|
|
|
<cfif usesSharding>
|
|
<!--- Get shard UUID for display --->
|
|
<cfquery name="qShard" datasource="payfrit">
|
|
SELECT UUID FROM BeaconShards WHERE ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#qBiz.BeaconShardID#">
|
|
</cfquery>
|
|
<cfset shardingInfo = {
|
|
"ShardID" = qBiz.BeaconShardID,
|
|
"ShardUUID" = qShard.recordCount GT 0 ? qShard.UUID : "",
|
|
"Major" = qBiz.BeaconMajor
|
|
}>
|
|
</cfif>
|
|
|
|
<!--- Legacy beacons from Beacons table --->
|
|
<cfquery name="q" datasource="payfrit">
|
|
SELECT DISTINCT
|
|
b.ID,
|
|
b.BusinessID,
|
|
b.Name,
|
|
b.UUID,
|
|
b.IsActive
|
|
FROM Beacons b
|
|
WHERE (
|
|
b.BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
|
|
OR b.ID IN (
|
|
SELECT lt.BeaconID FROM lt_BeaconsID_BusinessesID lt
|
|
WHERE lt.BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
|
|
)
|
|
)
|
|
<cfif onlyActive>
|
|
AND b.IsActive = 1
|
|
</cfif>
|
|
ORDER BY b.Name, b.ID
|
|
</cfquery>
|
|
|
|
<cfset beacons = []>
|
|
<cfloop query="q">
|
|
<cfset arrayAppend(beacons, {
|
|
"BeaconID" = q.ID,
|
|
"BusinessID" = q.BusinessID,
|
|
"Name" = q.Name,
|
|
"UUID" = q.UUID,
|
|
"IsActive" = q.IsActive,
|
|
"IsSharding" = false
|
|
})>
|
|
</cfloop>
|
|
|
|
<!--- If using sharding, also show service points with BeaconMinor as "beacons" --->
|
|
<cfif usesSharding>
|
|
<cfquery name="qShardBeacons" datasource="payfrit">
|
|
SELECT
|
|
sp.ID AS ServicePointID,
|
|
sp.Name,
|
|
sp.BeaconMinor,
|
|
sp.IsActive
|
|
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>
|
|
|
|
<cfloop query="qShardBeacons">
|
|
<cfset arrayAppend(beacons, {
|
|
"BeaconID" = 0,
|
|
"ServicePointID" = qShardBeacons.ServicePointID,
|
|
"BusinessID" = bizId,
|
|
"Name" = qShardBeacons.Name,
|
|
"UUID" = shardingInfo.ShardUUID,
|
|
"Major" = shardingInfo.Major,
|
|
"Minor" = qShardBeacons.BeaconMinor,
|
|
"IsActive" = qShardBeacons.IsActive,
|
|
"IsSharding" = true
|
|
})>
|
|
</cfloop>
|
|
</cfif>
|
|
|
|
<cfscript>try{logPerf(0);}catch(any e){}</cfscript>
|
|
<cfoutput>#serializeJSON({
|
|
OK=true,
|
|
ERROR="",
|
|
BusinessID=bizId,
|
|
COUNT=arrayLen(beacons),
|
|
BEACONS=beacons,
|
|
USES_SHARDING=usesSharding,
|
|
SHARDING_INFO=shardingInfo
|
|
})#</cfoutput>
|