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/admin/setupLazyDaisyBeacons.cfm
John Mizerek c62895e464 Fix prefixed column names in admin, beacon, task, assignment, chat, rating APIs
Updated all remaining SQL queries to use correct prefixed column names for
ServicePoints, Users, Businesses, Addresses, tt_States, tt_Days, and Hours
tables across 23 admin/infrastructure API files.

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

86 lines
3.2 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
response = { "OK": false, "steps": [] };
try {
lazyDaisyID = 37;
// Get all beacons
qBeacons = queryExecute("SELECT ID, UUID FROM Beacons", {}, { datasource: "payfrit" });
response.steps.append("Found " & qBeacons.recordCount & " beacons");
// Create service point for Table 1 if it doesn't exist
qSP = queryExecute("
SELECT ServicePointID AS ID FROM ServicePoints
WHERE ServicePointBusinessID = :bizID AND ServicePointName = 'Table 1'
", { bizID: lazyDaisyID }, { datasource: "payfrit" });
if (qSP.recordCount == 0) {
queryExecute("
INSERT INTO ServicePoints (ServicePointBusinessID, ServicePointName)
VALUES (:bizID, 'Table 1')
", { bizID: lazyDaisyID }, { datasource: "payfrit" });
qSP = queryExecute("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
servicePointID = qSP.id;
response.steps.append("Created service point 'Table 1' (ID: " & servicePointID & ")");
} else {
servicePointID = qSP.ID;
response.steps.append("Found existing service point 'Table 1' (ID: " & servicePointID & ")");
}
// Assign all beacons to the Table 1 service point
for (i = 1; i <= qBeacons.recordCount; i++) {
beaconID = qBeacons.ID[i];
// Unassign this beacon from any other service point first
queryExecute("
UPDATE ServicePoints SET BeaconID = NULL, AssignedByUserID = NULL
WHERE BeaconID = :beaconID
", { beaconID: beaconID }, { datasource: "payfrit" });
// Assign beacon to Table 1 service point
queryExecute("
UPDATE ServicePoints SET BeaconID = :beaconID, AssignedByUserID = 1
WHERE ServicePointID = :spID AND ServicePointBusinessID = :bizID
", { beaconID: beaconID, bizID: lazyDaisyID, spID: servicePointID }, { datasource: "payfrit" });
response.steps.append("Assigned beacon " & beaconID & " to Table 1");
}
// Get final status
qFinal = queryExecute("
SELECT sp.ServicePointID AS ServicePointID, sp.BeaconID, sp.ServicePointBusinessID AS BusinessID,
b.Name AS BeaconName, b.UUID, sp.ServicePointName AS ServicePointName,
biz.BusinessName AS BusinessName
FROM ServicePoints sp
JOIN Beacons b ON b.ID = sp.BeaconID
JOIN Businesses biz ON biz.BusinessID = sp.ServicePointBusinessID
WHERE sp.BeaconID IS NOT NULL
", {}, { datasource: "payfrit" });
beacons = [];
for (i = 1; i <= qFinal.recordCount; i++) {
arrayAppend(beacons, {
"BeaconID": qFinal.BeaconID[i],
"UUID": qFinal.UUID[i],
"BusinessID": qFinal.BusinessID[i],
"BusinessName": qFinal.BusinessName[i],
"ServicePointID": qFinal.ServicePointID[i],
"ServicePointName": qFinal.ServicePointName[i]
});
}
response.OK = true;
response.beacons = beacons;
} catch (any e) {
response.error = e.message;
if (len(e.detail)) {
response.detail = e.detail;
}
}
writeOutput(serializeJSON(response));
</cfscript>