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/ratings/listForAdmin.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

92 lines
3 KiB
Text

<cfsetting showdebugoutput="false">
<cfcontent type="application/json; charset=utf-8">
<cfscript>
/**
* List completed tasks that admin can rate
* Returns tasks completed in the last 7 days where admin hasn't yet rated the worker
*
* POST: { BusinessID: 123 }
*/
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 {};
}
}
try {
data = readJsonBody();
businessID = val(structKeyExists(data, "BusinessID") ? data.BusinessID : 0);
if (businessID == 0) {
writeOutput(serializeJSON({ "OK": false, "ERROR": "missing_business", "MESSAGE": "BusinessID is required." }));
abort;
}
// Get completed tasks from last 7 days where a worker was assigned
// and no admin rating exists yet
qTasks = queryExecute("
SELECT t.ID, t.Title, t.CompletedOn, t.ClaimedByUserID, t.OrderID,
u.FirstName AS WorkerFirstName, u.LastName AS WorkerLastName,
o.ID, o.UserID,
cu.FirstName AS CustomerFirstName, cu.LastName AS CustomerLastName,
sp.Name,
(SELECT COUNT(*) FROM TaskRatings r
WHERE r.TaskID = t.ID
AND r.Direction = 'admin_rates_worker') AS HasAdminRating
FROM Tasks t
INNER JOIN Users u ON u.ID = t.ClaimedByUserID
LEFT JOIN Orders o ON o.ID = t.OrderID
LEFT JOIN Users cu ON cu.ID = o.UserID
LEFT JOIN ServicePoints sp ON sp.ID = o.ServicePointID
WHERE t.BusinessID = :businessID
AND t.CompletedOn IS NOT NULL
AND t.CompletedOn > DATE_SUB(NOW(), INTERVAL 7 DAY)
AND t.ClaimedByUserID > 0
HAVING HasAdminRating = 0
ORDER BY t.CompletedOn DESC
LIMIT 50
", { businessID: businessID });
tasks = [];
for (row in qTasks) {
// Build task title
taskTitle = row.Title;
if (len(taskTitle) == 0 && row.OrderID > 0) {
taskTitle = "Order ##" & row.OrderID;
}
if (len(taskTitle) == 0) {
taskTitle = "Task ##" & row.TaskID;
}
arrayAppend(tasks, {
"TaskID": row.TaskID,
"Title": taskTitle,
"CompletedOn": dateTimeFormat(row.CompletedOn, "yyyy-mm-dd HH:nn:ss"),
"WorkerUserID": row.ClaimedByUserID,
"WorkerName": trim(row.WorkerFirstName & " " & row.WorkerLastName),
"CustomerName": len(row.CustomerFirstName) ? trim(row.CustomerFirstName & " " & row.CustomerLastName) : "",
"Name": row.Name ?: "",
"OrderID": row.OrderID ?: 0
});
}
writeOutput(serializeJSON({
"OK": true,
"TASKS": tasks
}));
} catch (any e) {
writeOutput(serializeJSON({
"OK": false,
"ERROR": "server_error",
"MESSAGE": "Error loading tasks",
"DETAIL": e.message
}));
}
</cfscript>