Add beacons/lookupByMac.php and beacons/wipe.php endpoints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
04d09cfc4e
commit
5d9be247c8
2 changed files with 91 additions and 0 deletions
47
api/beacons/lookupByMac.php
Normal file
47
api/beacons/lookupByMac.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../helpers.php';
|
||||
runAuth();
|
||||
|
||||
$data = readJsonBody();
|
||||
$macAddress = trim($data['MACAddress'] ?? '');
|
||||
|
||||
if ($macAddress === '') {
|
||||
apiAbort(['OK' => 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'] ?? '',
|
||||
],
|
||||
]);
|
||||
44
api/beacons/wipe.php
Normal file
44
api/beacons/wipe.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../helpers.php';
|
||||
runAuth();
|
||||
|
||||
global $businessId;
|
||||
|
||||
$data = readJsonBody();
|
||||
$bizId = $businessId;
|
||||
if ($bizId <= 0) $bizId = (int) ($data['BusinessID'] ?? 0);
|
||||
if ($bizId <= 0) {
|
||||
apiAbort(['OK' => 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]);
|
||||
Loading…
Add table
Reference in a new issue