Portal local development: - Add BASE_PATH detection to all portal files (login, portal.js, menu-builder, station-assignment) - Allows portal to work at /biz.payfrit.com/ path locally Menu Builder fixes: - Fix duplicate template options in getForBuilder.cfm query - Filter template children by business ID with DISTINCT New APIs: - api/portal/myBusinesses.cfm - List businesses for logged-in user - api/stations/list.cfm - List KDS stations - api/menu/updateStations.cfm - Update item station assignments - api/setup/reimportBigDeans.cfm - Full Big Dean's menu import script Admin utilities: - Various debug and migration scripts for menu/template management - Beacon switching, category cleanup, modifier template setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
2.3 KiB
Text
78 lines
2.3 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
|
|
<cffunction name="readJsonBody" access="public" returntype="struct" output="false">
|
|
<cfset var raw = getHttpRequestData().content>
|
|
<cfif isNull(raw) OR len(trim(raw)) EQ 0>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cftry>
|
|
<cfset var data = deserializeJSON(raw)>
|
|
<cfif isStruct(data)>
|
|
<cfreturn data>
|
|
<cfelse>
|
|
<cfreturn {}>
|
|
</cfif>
|
|
<cfcatch>
|
|
<cfreturn {}>
|
|
</cfcatch>
|
|
</cftry>
|
|
</cffunction>
|
|
|
|
<cffunction name="apiAbort" access="public" returntype="void" output="true">
|
|
<cfargument name="payload" type="struct" required="true">
|
|
<cfcontent type="application/json; charset=utf-8">
|
|
<cfoutput>#serializeJSON(arguments.payload)#</cfoutput>
|
|
<cfabort>
|
|
</cffunction>
|
|
|
|
<cfset data = readJsonBody()>
|
|
<cfset BusinessID = val( structKeyExists(data,"BusinessID") ? data.BusinessID : 0 )>
|
|
<cfset Assignments = structKeyExists(data,"Assignments") ? data.Assignments : []>
|
|
|
|
<cfif BusinessID LTE 0>
|
|
<cfset apiAbort({ "OK": false, "ERROR": "missing_businessid", "MESSAGE": "BusinessID is required." })>
|
|
</cfif>
|
|
|
|
<cftry>
|
|
<cfset updateCount = 0>
|
|
|
|
<!--- First, clear all station assignments for items in this business --->
|
|
<cfset queryExecute("
|
|
UPDATE Items i
|
|
INNER JOIN Categories c ON c.CategoryID = i.ItemCategoryID
|
|
SET i.ItemStationID = NULL
|
|
WHERE c.CategoryBusinessID = ?
|
|
", [ { value = BusinessID, cfsqltype = "cf_sql_integer" } ], { datasource = "payfrit" })>
|
|
|
|
<!--- Then apply the new assignments --->
|
|
<cfloop array="#Assignments#" index="assignment">
|
|
<cfif structKeyExists(assignment, "ItemID") AND structKeyExists(assignment, "StationID")>
|
|
<cfset queryExecute("
|
|
UPDATE Items
|
|
SET ItemStationID = ?
|
|
WHERE ItemID = ?
|
|
", [
|
|
{ value = assignment.StationID, cfsqltype = "cf_sql_integer" },
|
|
{ value = assignment.ItemID, cfsqltype = "cf_sql_integer" }
|
|
], { datasource = "payfrit" })>
|
|
<cfset updateCount++>
|
|
</cfif>
|
|
</cfloop>
|
|
|
|
<cfset apiAbort({
|
|
"OK": true,
|
|
"ERROR": "",
|
|
"MESSAGE": "Station assignments updated",
|
|
"UPDATED_COUNT": updateCount
|
|
})>
|
|
|
|
<cfcatch>
|
|
<cfset apiAbort({
|
|
"OK": false,
|
|
"ERROR": "server_error",
|
|
"MESSAGE": "Error updating stations",
|
|
"DETAIL": cfcatch.message
|
|
})>
|
|
</cfcatch>
|
|
</cftry>
|