/** * Save Business Order Types * POST JSON: { "BusinessID": 37, "OrderTypes": "1,2" } * OrderTypes is a comma-separated list: 1=Dine-In, 2=Takeaway, 3=Delivery */ response = { "OK": false }; try { requestBody = toString(getHttpRequestData().content); if (!len(requestBody)) { throw(message="No request body provided"); } data = deserializeJSON(requestBody); businessId = structKeyExists(data, "BusinessID") ? val(data.BusinessID) : 0; if (businessId == 0) { throw(message="BusinessID is required"); } orderTypes = structKeyExists(data, "OrderTypes") && isSimpleValue(data.OrderTypes) ? trim(data.OrderTypes) : "1"; // Validate: only allow digits 1-3 separated by commas if (!reFind("^[1-3](,[1-3])*$", orderTypes)) { throw(message="OrderTypes must be a comma-separated list of 1, 2, or 3"); } queryTimed(" UPDATE Businesses SET OrderTypes = :orderTypes WHERE ID = :bizId ", { orderTypes: { value: orderTypes, cfsqltype: "cf_sql_varchar" }, bizId: { value: businessId, cfsqltype: "cf_sql_integer" } }, { datasource: "payfrit" }); response.OK = true; response.OrderTypes = orderTypes; } catch (any e) { response.ERROR = e.message; } writeOutput(serializeJSON(response));