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/servicepoints/list.cfm
John Pinkyfloyd 0509e123e7 Add BeaconMinor support to servicepoints API
Allow setting/reading BeaconMinor on service points for beacon sharding
table assignment. Also fixes bug where save.cfm referenced qOut.ServicePointID
instead of qOut.ID.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-09 11:25:22 -08:00

141 lines
4.2 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>
// 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": "missing_businessid" });
}
// Default behavior: only active service points 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>
<cfquery name="q" datasource="payfrit">
SELECT
ID,
Name,
TypeID,
Code,
Description,
SortOrder,
IsActive,
BeaconMinor
FROM ServicePoints
WHERE BusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
<cfif onlyActive>
AND IsActive = 1
</cfif>
ORDER BY SortOrder, Name
</cfquery>
<cfset servicePoints = []>
<cfloop query="q">
<cfset arrayAppend(servicePoints, {
"ServicePointID" = q.ID,
"Name" = q.Name,
"TypeID" = q.TypeID,
"Code" = q.Code,
"Description" = q.Description,
"SortOrder" = q.SortOrder,
"IsActive" = q.IsActive,
"BeaconMinor" = val(q.BeaconMinor)
})>
</cfloop>
<!--- Query granted service points (SP-SM) --->
<cfinclude template="../grants/_grantUtils.cfm">
<cfset grantedServicePoints = []>
<cfquery name="qGranted" datasource="payfrit">
SELECT
sp.ID,
sp.Name,
sp.TypeID,
sp.Code,
sp.Description,
sp.SortOrder,
sp.IsActive,
g.ID AS GrantID,
g.OwnerBusinessID,
g.EconomicsType,
g.EconomicsValue,
g.EligibilityScope,
g.TimePolicyType,
g.TimePolicyData,
ob.Name AS OwnerBusinessName
FROM ServicePointGrants g
JOIN ServicePoints sp ON sp.ID = g.ServicePointID
JOIN Businesses ob ON ob.ID = g.OwnerBusinessID
WHERE g.GuestBusinessID = <cfqueryparam cfsqltype="cf_sql_integer" value="#bizId#">
AND g.StatusID = 1
AND sp.IsActive = 1
</cfquery>
<cfloop query="qGranted">
<cfif isGrantTimeActive(qGranted.TimePolicyType, qGranted.TimePolicyData)>
<cfset arrayAppend(grantedServicePoints, {
"ServicePointID" = qGranted.ID,
"Name" = qGranted.Name,
"TypeID" = qGranted.TypeID,
"Code" = qGranted.Code,
"Description" = qGranted.Description,
"SortOrder" = qGranted.SortOrder,
"IsActive" = qGranted.IsActive,
"IsGranted" = true,
"GrantID" = qGranted.GrantID,
"OwnerBusinessID" = qGranted.OwnerBusinessID,
"OwnerBusinessName" = qGranted.OwnerBusinessName,
"EconomicsType" = qGranted.EconomicsType,
"EconomicsValue" = qGranted.EconomicsValue,
"EligibilityScope" = qGranted.EligibilityScope
})>
</cfif>
</cfloop>
<cfoutput>#serializeJSON({
"OK": true,
"ERROR": "",
"BusinessID": bizId,
"COUNT": arrayLen(servicePoints),
"SERVICEPOINTS": servicePoints,
"GRANTED_COUNT": arrayLen(grantedServicePoints),
"GRANTED_SERVICEPOINTS": grantedServicePoints
})#</cfoutput>