- HUD now displays "Payfrit Tasks - <BusinessName>" by fetching from getBusiness API - Fixed portal Task HUD button to link to /hud/index.html instead of /hud/ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
94 lines
2.9 KiB
Text
94 lines
2.9 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;
|
|
}
|
|
|
|
function readJsonBody() {
|
|
raw = toString(getHttpRequestData().content);
|
|
if (isNull(raw) || len(trim(raw)) EQ 0) return {};
|
|
try {
|
|
parsed = deserializeJSON(raw);
|
|
} catch(any e) {
|
|
apiAbort({ OK=false, ERROR="bad_json", MESSAGE="Invalid JSON body" });
|
|
}
|
|
if (!isStruct(parsed)) return {};
|
|
return parsed;
|
|
}
|
|
|
|
data = readJsonBody();
|
|
|
|
if (!structKeyExists(data, "BeaconID") || !isNumeric(data.BeaconID) || int(data.BeaconID) LTE 0) {
|
|
apiAbort({ OK=false, ERROR="missing_beacon_id", MESSAGE="BeaconID is required" });
|
|
}
|
|
|
|
beaconId = int(data.BeaconID);
|
|
</cfscript>
|
|
|
|
<!--- Get beacon info first --->
|
|
<cfquery name="qBeacon" datasource="payfrit">
|
|
SELECT BeaconID, BeaconName, BeaconUUID, BeaconBusinessID
|
|
FROM Beacons
|
|
WHERE BeaconID = <cfqueryparam cfsqltype="cf_sql_integer" value="#beaconId#">
|
|
AND BeaconIsActive = 1
|
|
LIMIT 1
|
|
</cfquery>
|
|
|
|
<cfif qBeacon.recordCount EQ 0>
|
|
<cfoutput>#serializeJSON({ OK=false, ERROR="not_found", MESSAGE="Beacon not found or inactive" })#</cfoutput>
|
|
<cfabort>
|
|
</cfif>
|
|
|
|
<!--- Get all businesses that have assignments to this beacon --->
|
|
<!--- This includes the beacon owner AND any child businesses that have claimed this beacon --->
|
|
<cfquery name="qAssignments" datasource="payfrit">
|
|
SELECT
|
|
lt.BusinessID,
|
|
lt.ServicePointID,
|
|
biz.BusinessName,
|
|
biz.BusinessParentBusinessID,
|
|
sp.ServicePointName
|
|
FROM lt_Beacon_Businesses_ServicePoints lt
|
|
INNER JOIN Businesses biz ON biz.BusinessID = lt.BusinessID
|
|
INNER JOIN ServicePoints sp ON sp.ServicePointID = lt.ServicePointID
|
|
WHERE lt.BeaconID = <cfqueryparam cfsqltype="cf_sql_integer" value="#beaconId#">
|
|
AND sp.ServicePointIsActive = 1
|
|
ORDER BY biz.BusinessParentBusinessID IS NULL DESC, biz.BusinessName ASC
|
|
</cfquery>
|
|
|
|
<!--- Build response with array of businesses --->
|
|
<cfset businesses = []>
|
|
<cfloop query="qAssignments">
|
|
<cfset arrayAppend(businesses, {
|
|
"BusinessID" = qAssignments.BusinessID,
|
|
"BusinessName" = qAssignments.BusinessName,
|
|
"ServicePointID" = qAssignments.ServicePointID,
|
|
"ServicePointName" = qAssignments.ServicePointName,
|
|
"IsParent" = isNull(qAssignments.BusinessParentBusinessID) OR qAssignments.BusinessParentBusinessID EQ 0
|
|
})>
|
|
</cfloop>
|
|
|
|
<cfset response = {
|
|
"OK" = true,
|
|
"ERROR" = "",
|
|
"BEACON" = {
|
|
"BeaconID" = qBeacon.BeaconID,
|
|
"BeaconName" = qBeacon.BeaconName,
|
|
"UUID" = qBeacon.BeaconUUID
|
|
},
|
|
"BUSINESSES" = businesses,
|
|
"BUSINESS" = arrayLen(businesses) GT 0 ? businesses[1] : {},
|
|
"SERVICEPOINT" = arrayLen(businesses) GT 0 ? {
|
|
"ServicePointID" = businesses[1].ServicePointID,
|
|
"ServicePointName" = businesses[1].ServicePointName,
|
|
"ServicePointIsActive" = true
|
|
} : {}
|
|
}>
|
|
|
|
<cfoutput>#serializeJSON(response)#</cfoutput>
|