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.
36 lines
1 KiB
PHP
36 lines
1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Mark messages as read
|
|
* POST: { TaskID, ReaderType: "customer"|"worker" }
|
|
* Marks messages from the OTHER party as read
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$taskID = (int) ($data['TaskID'] ?? 0);
|
|
$readerType = strtolower(trim($data['ReaderType'] ?? ''));
|
|
|
|
if ($taskID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'TaskID is required']);
|
|
}
|
|
|
|
if ($readerType !== 'customer' && $readerType !== 'worker') {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => "ReaderType must be 'customer' or 'worker'"]);
|
|
}
|
|
|
|
try {
|
|
$otherType = ($readerType === 'customer') ? 'worker' : 'customer';
|
|
|
|
queryTimed("
|
|
UPDATE ChatMessages
|
|
SET IsRead = 1
|
|
WHERE TaskID = ? AND SenderType = ? AND IsRead = 0
|
|
", [$taskID, $otherType]);
|
|
|
|
jsonResponse(['OK' => true, 'MESSAGE' => 'Messages marked as read']);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|