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 39448c5d91 Fix prefixed column names in auth, orders, portal team, users search, workers APIs
Updated Users (UserID, UserFirstName, UserLastName, UserEmailAddress, UserContactNumber),
ServicePoints (ServicePointID, ServicePointName, ServicePointTypeID), and Businesses
(BusinessID, BusinessName, BusinessTaxRate, BusinessPhone) column references with proper
prefixed names and AS aliases for API compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 17:43:33 -08:00

109 lines
3.4 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.ServicePointName AS Name,
b.BusinessName AS BizName,
(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.ServicePointID = o.ServicePointID
LEFT JOIN Businesses b ON b.BusinessID = 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>