This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/orders/getPendingForUser.cfm
John Mizerek 1210249f54 Normalize database column and table names across entire codebase
Update all SQL queries, query result references, and ColdFusion code to match
the renamed database schema. Tables use plural CamelCase, PKs are all `ID`,
column prefixes stripped (e.g. BusinessName→Name, UserFirstName→FirstName).

Key changes:
- Strip table-name prefixes from all column references (Businesses, Users,
  Addresses, Hours, Menus, Categories, Items, Stations, Orders,
  OrderLineItems, Tasks, TaskCategories, TaskRatings, QuickTaskTemplates,
  ScheduledTaskDefinitions, ChatMessages, Beacons, ServicePoints, Employees,
  VisitorTrackings, ApiPerfLogs, tt_States, tt_Days, tt_AddressTypes,
  tt_OrderTypes, tt_TaskTypes)
- Rename PK references from {TableName}ID to ID in all queries
- Rewrite 7 admin beacon files to use ServicePoints.BeaconID instead of
  dropped lt_Beacon_Businesses_ServicePoints link table
- Rewrite beacon assignment files (list, save, delete) for new schema
- Fix FK references incorrectly changed to ID (OrderLineItems.OrderID,
  Categories.MenuID, Tasks.CategoryID, ServicePoints.BeaconID)
- Update Addresses: AddressLat→Latitude, AddressLng→Longitude
- Update Users: UserPassword→Password, UserIsEmailVerified→IsEmailVerified,
  UserIsActive→IsActive, UserBalance→Balance, etc.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 15:39:12 -08:00

109 lines
3.3 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 pending orders for a user at a specific business
* Used when a beacon is detected to check if user has an order to pick up
*
* Query params:
* UserID - the user's ID
* BusinessID - the business ID
*
* Returns orders with status 1-3 (Submitted, Preparing, Ready)
*/
response = { "OK": false };
try {
UserID = val(url.UserID ?: 0);
BusinessID = val(url.BusinessID ?: 0);
if (UserID LTE 0) {
response["ERROR"] = "missing_user";
response["MESSAGE"] = "UserID is required";
writeOutput(serializeJSON(response));
abort;
}
if (BusinessID LTE 0) {
response["ERROR"] = "missing_business";
response["MESSAGE"] = "BusinessID is required";
writeOutput(serializeJSON(response));
abort;
}
// Get orders with status 1 (Submitted), 2 (Preparing), or 3 (Ready)
// These are orders that are paid but not yet completed/picked up
qOrders = queryExecute("
SELECT
o.ID,
o.UUID,
o.OrderTypeID,
o.StatusID,
o.SubmittedOn,
o.ServicePointID,
sp.Name,
b.Name,
(SELECT COALESCE(SUM(oli.Price * oli.Quantity), 0)
FROM OrderLineItems oli
WHERE oli.OrderID = o.ID
AND oli.IsDeleted = 0
AND oli.ParentOrderLineItemID = 0) as Subtotal
FROM Orders o
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
LEFT JOIN Businesses b ON b.ID = o.BusinessID
WHERE o.UserID = :userId
AND o.BusinessID = :businessId
AND o.StatusID IN (1, 2, 3)
ORDER BY o.SubmittedOn DESC
LIMIT 5
", {
userId: { value: UserID, cfsqltype: "cf_sql_integer" },
businessId: { value: BusinessID, cfsqltype: "cf_sql_integer" }
}, { datasource: "payfrit" });
orders = [];
for (row in qOrders) {
statusName = "";
switch (row.StatusID) {
case 1: statusName = "Submitted"; break;
case 2: statusName = "Preparing"; break;
case 3: statusName = "Ready for Pickup"; break;
}
orderTypeName = "";
switch (row.OrderTypeID) {
case 1: orderTypeName = "Dine-In"; break;
case 2: orderTypeName = "Takeaway"; break;
case 3: orderTypeName = "Delivery"; break;
}
arrayAppend(orders, {
"OrderID": row.ID,
"UUID": row.UUID,
"OrderTypeID": row.OrderTypeID,
"OrderTypeName": orderTypeName,
"StatusID": row.StatusID,
"StatusName": statusName,
"SubmittedOn": dateTimeFormat(row.SubmittedOn, "yyyy-mm-dd HH:nn:ss"),
"ServicePointID": row.ServicePointID,
"Name": len(trim(row.Name)) ? row.Name : "",
"Name": len(trim(row.Name)) ? row.Name : "",
"Subtotal": row.Subtotal
});
}
response["OK"] = true;
response["ORDERS"] = orders;
response["HAS_PENDING"] = arrayLen(orders) GT 0;
} catch (any e) {
response["ERROR"] = "server_error";
response["MESSAGE"] = e.message;
}
writeOutput(serializeJSON(response));
</cfscript>