diff --git a/api/beacons/lookupByMac.php b/api/beacons/lookupByMac.php new file mode 100644 index 0000000..acc5aa0 --- /dev/null +++ b/api/beacons/lookupByMac.php @@ -0,0 +1,47 @@ + false, 'ERROR' => 'missing_mac', 'MESSAGE' => 'MACAddress is required']); +} + +$q = queryOne(" + SELECT + bh.ID AS BeaconHardwareID, + bh.HardwareId AS MACAddress, + bh.BusinessID, + bh.ServicePointID, + bh.ShardUUID AS UUID, + bh.Major, + bh.Minor, + bh.Status, + biz.Name AS BusinessName, + sp.Name AS ServicePointName + FROM BeaconHardware bh + LEFT JOIN Businesses biz ON biz.ID = bh.BusinessID + LEFT JOIN ServicePoints sp ON sp.ID = bh.ServicePointID + WHERE bh.HardwareId = ? + LIMIT 1 +", [$macAddress]); + +if (!$q || $q['Status'] !== 'assigned') { + jsonResponse(['OK' => false, 'ERROR' => 'not_found']); +} + +jsonResponse([ + 'OK' => true, + 'ERROR' => '', + 'BEACON' => [ + 'BeaconID' => (int) $q['BeaconHardwareID'], + 'BusinessID' => (int) $q['BusinessID'], + 'BusinessName' => $q['BusinessName'] ?? '', + 'BeaconName' => $q['ServicePointName'] ?? '', + 'UUID' => $q['UUID'] ?? '', + 'MACAddress' => $q['MACAddress'], + 'ServicePointName' => $q['ServicePointName'] ?? '', + ], +]); diff --git a/api/beacons/wipe.php b/api/beacons/wipe.php new file mode 100644 index 0000000..c2f4e0d --- /dev/null +++ b/api/beacons/wipe.php @@ -0,0 +1,44 @@ + false, 'ERROR' => 'no_business_selected']); +} + +$beaconId = (int) ($data['BeaconID'] ?? 0); +if ($beaconId <= 0) { + apiAbort(['OK' => false, 'ERROR' => 'missing_beacon_id', 'MESSAGE' => 'BeaconID is required']); +} + +$q = queryOne(" + SELECT ID, BusinessID, ServicePointID FROM BeaconHardware + WHERE ID = ? AND BusinessID = ? + LIMIT 1 +", [$beaconId, $bizId]); + +if (!$q) { + apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Beacon not found or does not belong to this business']); +} + +$servicePointId = (int) ($q['ServicePointID'] ?? 0); + +// Clear the minor from the service point so it can be re-provisioned +if ($servicePointId > 0) { + queryTimed("UPDATE ServicePoints SET BeaconMinor = NULL WHERE ID = ? AND BusinessID = ?", [$servicePointId, $bizId]); +} + +// Mark hardware as unassigned +queryTimed(" + UPDATE BeaconHardware + SET Status = 'unassigned', BusinessID = NULL, ServicePointID = NULL, + ShardUUID = NULL, Major = NULL, Minor = NULL, UpdatedAt = NOW() + WHERE ID = ? +", [$beaconId]); + +jsonResponse(['OK' => true, 'ERROR' => '', 'BeaconID' => $beaconId]);