Features: - Multi-menu support with time-based availability - Menu hours validation against business operating hours - Setup wizard now creates Menu records and links categories - New menus.cfm API for menu CRUD operations - Category schedule filtering (day/time based visibility) - Beacon UUID lookup API for customer app - Parent/child business relationships for franchises - Category listing API for menu builder Portal improvements: - Menu builder theming to match admin UI - Brand color picker fix - Header image preview improvements API fixes: - Filter demo/hidden businesses from restaurant list - Improved error handling throughout Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
119 lines
3.7 KiB
Text
119 lines
3.7 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>
|
|
/**
|
|
* Create Parent Business (Shell)
|
|
*
|
|
* Creates a minimal business record to serve as a parent for other businesses.
|
|
* No menu items, categories, or hours required.
|
|
*
|
|
* POST body:
|
|
* {
|
|
* "BusinessName": "Century Casino",
|
|
* "UserID": 1,
|
|
* "ChildBusinessIDs": [47, 48] // Optional: link existing businesses as children
|
|
* }
|
|
*
|
|
* Returns the new BusinessID
|
|
*/
|
|
|
|
function readJsonBody() {
|
|
var raw = getHttpRequestData().content;
|
|
if (isNull(raw) || len(trim(raw)) == 0) return {};
|
|
try {
|
|
var data = deserializeJSON(raw);
|
|
return isStruct(data) ? data : {};
|
|
} catch (any e) {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
response = { "OK": false };
|
|
|
|
try {
|
|
data = readJsonBody();
|
|
|
|
BusinessName = structKeyExists(data, "BusinessName") ? trim(data.BusinessName) : "";
|
|
UserID = structKeyExists(data, "UserID") ? val(data.UserID) : 0;
|
|
ChildBusinessIDs = structKeyExists(data, "ChildBusinessIDs") && isArray(data.ChildBusinessIDs) ? data.ChildBusinessIDs : [];
|
|
|
|
if (!len(BusinessName)) {
|
|
response["ERROR"] = "missing_name";
|
|
response["MESSAGE"] = "BusinessName is required";
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
if (UserID <= 0) {
|
|
response["ERROR"] = "missing_userid";
|
|
response["MESSAGE"] = "UserID is required";
|
|
writeOutput(serializeJSON(response));
|
|
abort;
|
|
}
|
|
|
|
// Create minimal address record (just a placeholder)
|
|
queryExecute("
|
|
INSERT INTO Addresses (AddressLine1, AddressUserID, AddressTypeID, AddressAddedOn)
|
|
VALUES ('Parent Business - No Physical Location', :userID, 2, NOW())
|
|
", {
|
|
userID: UserID
|
|
}, { datasource = "payfrit" });
|
|
|
|
qAddr = queryExecute("SELECT LAST_INSERT_ID() as id", {}, { datasource = "payfrit" });
|
|
addressId = qAddr.id;
|
|
|
|
// Create parent business (no menu, no hours, just a shell)
|
|
queryExecute("
|
|
INSERT INTO Businesses (BusinessName, BusinessUserID, BusinessAddressID, BusinessParentBusinessID, BusinessDeliveryZipCodes, BusinessAddedOn)
|
|
VALUES (:name, :userId, :addressId, NULL, '', NOW())
|
|
", {
|
|
name: BusinessName,
|
|
userId: UserID,
|
|
addressId: addressId
|
|
}, { datasource = "payfrit" });
|
|
|
|
qBiz = queryExecute("SELECT LAST_INSERT_ID() as id", {}, { datasource = "payfrit" });
|
|
newBusinessID = qBiz.id;
|
|
|
|
// Link address back to business
|
|
queryExecute("
|
|
UPDATE Addresses SET AddressBusinessID = :bizId WHERE AddressID = :addrId
|
|
", {
|
|
bizId: newBusinessID,
|
|
addrId: addressId
|
|
}, { datasource = "payfrit" });
|
|
|
|
// Update child businesses if provided
|
|
linkedChildren = [];
|
|
for (childID in ChildBusinessIDs) {
|
|
childID = val(childID);
|
|
if (childID > 0) {
|
|
queryExecute("
|
|
UPDATE Businesses SET BusinessParentBusinessID = :parentId WHERE BusinessID = :childId
|
|
", {
|
|
parentId: newBusinessID,
|
|
childId: childID
|
|
}, { datasource = "payfrit" });
|
|
arrayAppend(linkedChildren, childID);
|
|
}
|
|
}
|
|
|
|
response["OK"] = true;
|
|
response["BusinessID"] = newBusinessID;
|
|
response["BusinessName"] = BusinessName;
|
|
response["MESSAGE"] = "Parent business created";
|
|
if (arrayLen(linkedChildren) > 0) {
|
|
response["LinkedChildren"] = linkedChildren;
|
|
}
|
|
|
|
} catch (any e) {
|
|
response["ERROR"] = "server_error";
|
|
response["MESSAGE"] = e.message;
|
|
response["DETAIL"] = e.detail;
|
|
}
|
|
|
|
writeOutput(serializeJSON(response));
|
|
</cfscript>
|