payfrit-api/api/assignments/delete.php
John Mizerek 1f81d98c52 Initial PHP API migration from CFML
Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3.
Shared helpers in api/helpers.php (DB, auth, request/response, security).
PDO prepared statements throughout. Same JSON response shapes as CFML.
2026-03-14 14:26:59 -07:00

43 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../helpers.php';
runAuth();
global $businessId;
if ($businessId <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'no_business_selected']);
}
$data = readJsonBody();
$servicePointID = (int) ($data['ServicePointID'] ?? 0);
if ($servicePointID <= 0) {
apiAbort(['OK' => false, 'ERROR' => 'missing_ServicePointID']);
}
$qFind = queryOne("
SELECT ID, BeaconID FROM ServicePoints
WHERE ID = ? AND BusinessID = ? AND BeaconID IS NOT NULL
LIMIT 1
", [$servicePointID, $businessId]);
if (!$qFind) {
apiAbort([
'OK' => false, 'ERROR' => 'not_found',
'ServicePointID' => $servicePointID,
'BusinessID' => (string) $businessId,
]);
}
$removedBeaconID = (int) $qFind['BeaconID'];
queryTimed("UPDATE ServicePoints SET BeaconID = NULL, AssignedByUserID = NULL WHERE ID = ? AND BusinessID = ?",
[$servicePointID, $businessId]);
jsonResponse([
'OK' => true, 'ERROR' => '',
'ACTION' => 'unassigned',
'ServicePointID' => $servicePointID,
'BeaconID' => $removedBeaconID,
'BusinessID' => (string) $businessId,
]);