payfrit-works/api/portal/myBusinesses.cfm
John Mizerek 51a80b537d Add local dev support and fix menu builder API
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>
2026-01-04 22:47:12 -08:00

75 lines
1.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>
/**
* Get Businesses for User
* Returns list of businesses the authenticated user has access to
*
* POST: { UserID: int }
* Headers: X-User-Token (optional - will use session if not provided)
*/
response = { "OK": false };
try {
// Get UserID from request or session
userID = 0;
// Check token auth first
if (structKeyExists(request, "UserID") && isNumeric(request.UserID)) {
userID = int(request.UserID);
}
// Also check request body
if (userID == 0) {
requestBody = toString(getHttpRequestData().content);
if (len(requestBody)) {
requestData = deserializeJSON(requestBody);
if (structKeyExists(requestData, "UserID")) {
userID = val(requestData.UserID);
}
}
}
if (userID == 0) {
response["ERROR"] = "not_logged_in";
response["MESSAGE"] = "User not authenticated";
writeOutput(serializeJSON(response));
abort;
}
// Get businesses for this user
// Users are linked to businesses via BusinessUserID field (owner)
q = queryExecute("
SELECT
b.BusinessID,
b.BusinessName
FROM Businesses b
WHERE b.BusinessUserID = :userID
ORDER BY b.BusinessName
", { userID: userID }, { datasource: "payfrit" });
businesses = [];
for (row in q) {
arrayAppend(businesses, {
"BusinessID": row.BusinessID,
"BusinessName": row.BusinessName
});
}
response["OK"] = true;
response["BUSINESSES"] = businesses;
response["COUNT"] = arrayLen(businesses);
} catch (any e) {
response["ERROR"] = "server_error";
response["MESSAGE"] = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>