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/cleanupBeacons.cfm
John Mizerek 8acf2f3249 Complete DB column normalization: strip redundant table-name prefixes from all SQL queries
Updated 70 files to match the payfrit_dev schema where columns like
BusinessName→Name, UserFirstName→FirstName, AddressCity→City, etc.
PKs renamed to ID, FKs keep referenced table name (e.g. BusinessID).
SQL aliases preserve original JSON response keys for API compatibility.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-31 20:03:40 -08:00

86 lines
2.9 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
/**
* Cleanup Lazy Daisy Beacons
* - Unassigns beacons 7, 8, 9 from service points
* - Deletes beacons 7, 8, 9
* - Updates original beacons with proper names
*/
response = { "OK": false, "steps": [] };
try {
lazyDaisyID = 37;
// Unassign beacons 7, 8, 9 from any service points
queryExecute("
UPDATE ServicePoints
SET BeaconID = NULL, AssignedByUserID = NULL
WHERE BeaconID IN (7, 8, 9) AND BusinessID = :bizId
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Unassigned beacons 7, 8, 9 from service points");
// Delete duplicate beacons 7, 8, 9
queryExecute("
DELETE FROM Beacons
WHERE ID IN (7, 8, 9) AND BusinessID = :bizId
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Deleted duplicate beacons 7, 8, 9");
// Update original beacons with names based on their service point assignments
queryExecute("
UPDATE Beacons SET Name = 'Beacon - Table 1'
WHERE ID = 4 AND BusinessID = :bizId
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Updated Beacon 4 name to 'Beacon - Table 1'");
queryExecute("
UPDATE Beacons SET Name = 'Beacon - Table 2'
WHERE ID = 5 AND BusinessID = :bizId
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Updated Beacon 5 name to 'Beacon - Table 2'");
queryExecute("
UPDATE Beacons SET Name = 'Beacon - Table 3'
WHERE ID = 6 AND BusinessID = :bizId
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Updated Beacon 6 name to 'Beacon - Table 3'");
// Get final status
qFinal = queryExecute("
SELECT sp.ID AS ServicePointID, sp.BeaconID, sp.BusinessID AS BusinessID,
b.Name AS BeaconName, b.UUID, sp.Name AS ServicePointName,
biz.Name AS BusinessName
FROM ServicePoints sp
JOIN Beacons b ON b.ID = sp.BeaconID
JOIN Businesses biz ON biz.ID = sp.BusinessID
WHERE sp.BusinessID = :bizId AND sp.BeaconID IS NOT NULL
ORDER BY sp.BeaconID
", { bizId: lazyDaisyID }, { datasource: "payfrit" });
beacons = [];
for (i = 1; i <= qFinal.recordCount; i++) {
arrayAppend(beacons, {
"BeaconID": qFinal.BeaconID[i],
"BeaconName": qFinal.BeaconName[i],
"UUID": qFinal.UUID[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>