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/setupBeaconTables.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

106 lines
3.8 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
/**
* Setup Lazy Daisy Beacons
* Creates a beacon for each service point and assigns them
*/
response = { "OK": false, "steps": [] };
try {
lazyDaisyID = 37;
// Get all service points for Lazy Daisy
qServicePoints = queryExecute("
SELECT ServicePointID AS ID, ServicePointName AS Name
FROM ServicePoints
WHERE ServicePointBusinessID = :bizID AND IsActive = 1
ORDER BY SortOrder, ServicePointID
", { bizID: lazyDaisyID }, { datasource: "payfrit" });
response.steps.append("Found " & qServicePoints.recordCount & " service points for Lazy Daisy");
// Create a beacon for each service point
beaconsCreated = 0;
for (sp in qServicePoints) {
beaconName = "Beacon - " & sp.Name;
// Check if beacon already exists for this business with this name
qExisting = queryExecute("
SELECT ID FROM Beacons
WHERE BusinessID = :bizId AND Name = :name
", { bizId: lazyDaisyID, name: beaconName }, { datasource: "payfrit" });
if (qExisting.recordCount == 0) {
// Generate a unique UUID for this beacon (32 hex chars, no dashes)
beaconUUID = "PAYFRIT00037" & numberFormat(sp.ID, "0000000000000000000");
queryExecute("
INSERT INTO Beacons (BusinessID, Name, UUID, IsActive)
VALUES (:bizId, :name, :uuid, 1)
", {
bizId: lazyDaisyID,
name: beaconName,
uuid: beaconUUID
}, { datasource: "payfrit" });
qNewBeacon = queryExecute("SELECT LAST_INSERT_ID() as id", {}, { datasource: "payfrit" });
newBeaconId = qNewBeacon.id;
// Assign beacon directly to service point
queryExecute("
UPDATE ServicePoints
SET BeaconID = :beaconId, AssignedByUserID = 1
WHERE ServicePointID = :spId AND ServicePointBusinessID = :bizId
", {
beaconId: newBeaconId,
bizId: lazyDaisyID,
spId: sp.ID
}, { datasource: "payfrit" });
response.steps.append("Created beacon '" & beaconName & "' (ID: " & newBeaconId & ") -> " & sp.Name);
beaconsCreated++;
} else {
response.steps.append("Beacon '" & beaconName & "' already exists, skipping");
}
}
// 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.ServicePointBusinessID = :bizId AND sp.BeaconID IS NOT NULL
ORDER BY sp.ServicePointName
", { 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.beaconsCreated = beaconsCreated;
response.beacons = beacons;
} catch (any e) {
response.error = e.message;
if (len(e.detail)) {
response.detail = e.detail;
}
}
writeOutput(serializeJSON(response));
</cfscript>