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>
152 lines
5.8 KiB
Text
152 lines
5.8 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
<cfcontent type="application/json; charset=utf-8" reset="true">
|
|
|
|
<cfscript>
|
|
// Create or update a task type for a business
|
|
// Input: BusinessID (required), TaskTypeName (required), TaskTypeDescription (optional), TaskTypeIcon (optional), TaskTypeID (optional - for update)
|
|
// Output: { OK: true, TASK_TYPE_ID: ... }
|
|
|
|
function apiAbort(required struct payload) {
|
|
writeOutput(serializeJSON(payload));
|
|
abort;
|
|
}
|
|
|
|
function readJsonBody() {
|
|
var raw = getHttpRequestData().content;
|
|
if (isNull(raw)) raw = "";
|
|
if (!len(trim(raw))) return {};
|
|
try {
|
|
var data = deserializeJSON(raw);
|
|
if (isStruct(data)) return data;
|
|
} catch (any e) {}
|
|
return {};
|
|
}
|
|
|
|
try {
|
|
data = readJsonBody();
|
|
|
|
// Get BusinessID
|
|
businessID = 0;
|
|
if (structKeyExists(data, "BusinessID") && isNumeric(data.BusinessID)) {
|
|
businessID = int(data.BusinessID);
|
|
}
|
|
if (businessID == 0) {
|
|
apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "BusinessID is required" });
|
|
}
|
|
|
|
// Get TaskTypeName
|
|
taskTypeName = "";
|
|
if (structKeyExists(data, "TaskTypeName")) {
|
|
taskTypeName = trim(toString(data.TaskTypeName));
|
|
}
|
|
if (!len(taskTypeName)) {
|
|
apiAbort({ "OK": false, "ERROR": "missing_params", "MESSAGE": "TaskTypeName is required" });
|
|
}
|
|
if (len(taskTypeName) > 45) {
|
|
apiAbort({ "OK": false, "ERROR": "invalid_params", "MESSAGE": "TaskTypeName must be 45 characters or less" });
|
|
}
|
|
|
|
// Get TaskTypeDescription (optional)
|
|
taskTypeDescription = "";
|
|
if (structKeyExists(data, "TaskTypeDescription")) {
|
|
taskTypeDescription = trim(toString(data.TaskTypeDescription));
|
|
}
|
|
if (len(taskTypeDescription) > 100) {
|
|
apiAbort({ "OK": false, "ERROR": "invalid_params", "MESSAGE": "TaskTypeDescription must be 100 characters or less" });
|
|
}
|
|
|
|
// Get TaskTypeIcon (optional, default to 'notifications')
|
|
taskTypeIcon = "notifications";
|
|
if (structKeyExists(data, "TaskTypeIcon") && len(trim(toString(data.TaskTypeIcon)))) {
|
|
taskTypeIcon = trim(toString(data.TaskTypeIcon));
|
|
}
|
|
if (len(taskTypeIcon) > 30) {
|
|
apiAbort({ "OK": false, "ERROR": "invalid_params", "MESSAGE": "TaskTypeIcon must be 30 characters or less" });
|
|
}
|
|
|
|
// Get TaskTypeColor (optional, default to purple)
|
|
taskTypeColor = "##9C27B0";
|
|
if (structKeyExists(data, "TaskTypeColor") && len(trim(toString(data.TaskTypeColor)))) {
|
|
taskTypeColor = trim(toString(data.TaskTypeColor));
|
|
// Ensure it starts with # (incoming JSON has single #, we store single #)
|
|
if (left(taskTypeColor, 1) != chr(35)) {
|
|
taskTypeColor = chr(35) & taskTypeColor;
|
|
}
|
|
}
|
|
if (len(taskTypeColor) > 7) {
|
|
apiAbort({ "OK": false, "ERROR": "invalid_params", "MESSAGE": "TaskTypeColor must be a valid hex color" });
|
|
}
|
|
|
|
// Get TaskTypeID (optional - for update)
|
|
taskTypeID = 0;
|
|
if (structKeyExists(data, "TaskTypeID") && isNumeric(data.TaskTypeID)) {
|
|
taskTypeID = int(data.TaskTypeID);
|
|
}
|
|
|
|
if (taskTypeID > 0) {
|
|
// UPDATE - verify it belongs to this business
|
|
qCheck = queryExecute("
|
|
SELECT tt_TaskTypeID FROM tt_TaskTypes
|
|
WHERE tt_TaskTypeID = :taskTypeID
|
|
AND tt_TaskTypeBusinessID = :businessID
|
|
", {
|
|
taskTypeID: { value: taskTypeID, cfsqltype: "cf_sql_integer" },
|
|
businessID: { value: businessID, cfsqltype: "cf_sql_integer" }
|
|
}, { datasource: "payfrit" });
|
|
|
|
if (qCheck.recordCount == 0) {
|
|
apiAbort({ "OK": false, "ERROR": "not_found", "MESSAGE": "Task type not found or does not belong to this business" });
|
|
}
|
|
|
|
queryExecute("
|
|
UPDATE tt_TaskTypes
|
|
SET tt_TaskTypeName = :taskTypeName,
|
|
tt_TaskTypeDescription = :taskTypeDescription,
|
|
tt_TaskTypeIcon = :taskTypeIcon,
|
|
tt_TaskTypeColor = :taskTypeColor
|
|
WHERE tt_TaskTypeID = :taskTypeID
|
|
", {
|
|
taskTypeName: { value: taskTypeName, cfsqltype: "cf_sql_varchar" },
|
|
taskTypeDescription: { value: taskTypeDescription, cfsqltype: "cf_sql_varchar", null: !len(taskTypeDescription) },
|
|
taskTypeIcon: { value: taskTypeIcon, cfsqltype: "cf_sql_varchar" },
|
|
taskTypeColor: { value: taskTypeColor, cfsqltype: "cf_sql_varchar" },
|
|
taskTypeID: { value: taskTypeID, cfsqltype: "cf_sql_integer" }
|
|
}, { datasource: "payfrit" });
|
|
|
|
apiAbort({
|
|
"OK": true,
|
|
"TASK_TYPE_ID": taskTypeID,
|
|
"MESSAGE": "Task type updated"
|
|
});
|
|
} else {
|
|
// INSERT new task type
|
|
queryExecute("
|
|
INSERT INTO tt_TaskTypes (tt_TaskTypeName, tt_TaskTypeDescription, tt_TaskTypeIcon, tt_TaskTypeColor, tt_TaskTypeBusinessID)
|
|
VALUES (:taskTypeName, :taskTypeDescription, :taskTypeIcon, :taskTypeColor, :businessID)
|
|
", {
|
|
taskTypeName: { value: taskTypeName, cfsqltype: "cf_sql_varchar" },
|
|
taskTypeDescription: { value: taskTypeDescription, cfsqltype: "cf_sql_varchar", null: !len(taskTypeDescription) },
|
|
taskTypeIcon: { value: taskTypeIcon, cfsqltype: "cf_sql_varchar" },
|
|
taskTypeColor: { value: taskTypeColor, cfsqltype: "cf_sql_varchar" },
|
|
businessID: { value: businessID, cfsqltype: "cf_sql_integer" }
|
|
}, { datasource: "payfrit" });
|
|
|
|
qNew = queryExecute("SELECT LAST_INSERT_ID() as newID", [], { datasource: "payfrit" });
|
|
newID = qNew.newID;
|
|
|
|
apiAbort({
|
|
"OK": true,
|
|
"TASK_TYPE_ID": newID,
|
|
"MESSAGE": "Task type created"
|
|
});
|
|
}
|
|
|
|
} catch (any e) {
|
|
apiAbort({
|
|
"OK": false,
|
|
"ERROR": "server_error",
|
|
"MESSAGE": e.message
|
|
});
|
|
}
|
|
</cfscript>
|