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.
57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Update Station Assignments
|
|
*
|
|
* POST body:
|
|
* {
|
|
* "BusinessID": 37,
|
|
* "Assignments": [
|
|
* { "ItemID": 1, "StationID": 5 },
|
|
* { "ItemID": 2, "StationID": 5 }
|
|
* ]
|
|
* }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$businessID = (int) ($data['BusinessID'] ?? 0);
|
|
$assignments = $data['Assignments'] ?? [];
|
|
|
|
if ($businessID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_businessid', 'MESSAGE' => 'BusinessID is required.']);
|
|
}
|
|
|
|
try {
|
|
$updateCount = 0;
|
|
|
|
// Clear all station assignments for items in this business
|
|
queryTimed("UPDATE Items SET StationID = NULL WHERE BusinessID = ?", [$businessID]);
|
|
|
|
// Apply new assignments
|
|
foreach ($assignments as $assignment) {
|
|
if (isset($assignment['ItemID'], $assignment['StationID'])) {
|
|
queryTimed("UPDATE Items SET StationID = ? WHERE ID = ?", [
|
|
(int) $assignment['StationID'],
|
|
(int) $assignment['ItemID'],
|
|
]);
|
|
$updateCount++;
|
|
}
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'ERROR' => '',
|
|
'MESSAGE' => 'Station assignments updated',
|
|
'UPDATED_COUNT' => $updateCount,
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse([
|
|
'OK' => false,
|
|
'ERROR' => 'server_error',
|
|
'MESSAGE' => 'Error updating stations',
|
|
'DETAIL' => $e->getMessage(),
|
|
]);
|
|
}
|