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.
53 lines
1.3 KiB
PHP
53 lines
1.3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Accept/claim a task
|
|
* POST: { TaskID: int }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$taskID = (int) ($data['TaskID'] ?? 0);
|
|
|
|
if ($taskID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'TaskID is required.']);
|
|
}
|
|
|
|
try {
|
|
global $userId;
|
|
|
|
// Verify task exists and is unclaimed
|
|
$qTask = queryOne("
|
|
SELECT ID, ClaimedByUserID, BusinessID, OrderID
|
|
FROM Tasks
|
|
WHERE ID = ?
|
|
", [$taskID]);
|
|
|
|
if (!$qTask) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Task not found.']);
|
|
}
|
|
|
|
if ((int) $qTask['ClaimedByUserID'] > 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'already_accepted', 'MESSAGE' => 'Task has already been claimed.']);
|
|
}
|
|
|
|
// Update task to claimed
|
|
queryTimed("
|
|
UPDATE Tasks
|
|
SET ClaimedByUserID = ?,
|
|
ClaimedOn = NOW()
|
|
WHERE ID = ?
|
|
AND ClaimedByUserID = 0
|
|
", [$userId > 0 ? $userId : 1, $taskID]);
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'ERROR' => '',
|
|
'MESSAGE' => 'Task claimed successfully.',
|
|
'TaskID' => $taskID,
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => 'Error claiming task', 'DETAIL' => $e->getMessage()]);
|
|
}
|