/** * Cleanup Lazy Daisy Beacons * - Removes duplicate beacons created by setupBeaconTables * - Updates original beacons with proper names */ response = { "OK": false, "steps": [] }; try { lazyDaisyID = 37; // Delete duplicate assignments for beacons 7, 8, 9 queryExecute(" DELETE FROM lt_Beacon_Businesses_ServicePoints WHERE BeaconID IN (7, 8, 9) AND BusinessID = :bizId ", { bizId: lazyDaisyID }, { datasource: "payfrit" }); response.steps.append("Deleted duplicate assignments for beacons 7, 8, 9"); // Delete duplicate beacons 7, 8, 9 queryExecute(" DELETE FROM Beacons WHERE BeaconID IN (7, 8, 9) AND BeaconBusinessID = :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 // Beacon 4 -> Table 1 (ServicePointID 4) // Beacon 5 -> Table 2 (ServicePointID 5) // Beacon 6 -> Table 3 (ServicePointID 6) queryExecute(" UPDATE Beacons SET BeaconName = 'Beacon - Table 1' WHERE BeaconID = 4 AND BeaconBusinessID = :bizId ", { bizId: lazyDaisyID }, { datasource: "payfrit" }); response.steps.append("Updated Beacon 4 name to 'Beacon - Table 1'"); queryExecute(" UPDATE Beacons SET BeaconName = 'Beacon - Table 2' WHERE BeaconID = 5 AND BeaconBusinessID = :bizId ", { bizId: lazyDaisyID }, { datasource: "payfrit" }); response.steps.append("Updated Beacon 5 name to 'Beacon - Table 2'"); queryExecute(" UPDATE Beacons SET BeaconName = 'Beacon - Table 3' WHERE BeaconID = 6 AND BeaconBusinessID = :bizId ", { bizId: lazyDaisyID }, { datasource: "payfrit" }); response.steps.append("Updated Beacon 6 name to 'Beacon - Table 3'"); // Get final status qFinal = queryExecute(" SELECT lt.BeaconID, b.BeaconUUID, b.BeaconName, lt.BusinessID, biz.BusinessName, lt.ServicePointID, sp.ServicePointName FROM lt_Beacon_Businesses_ServicePoints lt JOIN Beacons b ON b.BeaconID = lt.BeaconID JOIN Businesses biz ON biz.BusinessID = lt.BusinessID LEFT JOIN ServicePoints sp ON sp.ServicePointID = lt.ServicePointID WHERE lt.BusinessID = :bizId ORDER BY lt.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.BeaconUUID[i], "BusinessName": qFinal.BusinessName[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));