Update: 2026-05-08 01:41:28
This commit is contained in:
28
app/modules_app/notifications/read.php
Normal file
28
app/modules_app/notifications/read.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Mark Notification(s) as Read
|
||||
* POST /v1/notifications/read
|
||||
*/
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Middleware\AuthMiddleware;
|
||||
|
||||
$decoded = AuthMiddleware::check();
|
||||
$data = input();
|
||||
$db = Database::getInstance();
|
||||
|
||||
$userId = $decoded['user_id'];
|
||||
$id = $data['id'] ?? null;
|
||||
$markAll = $data['mark_all'] ?? false;
|
||||
|
||||
if ($markAll) {
|
||||
$db->prepare("UPDATE notifications SET is_read = 1, read_at = NOW() WHERE user_id = ? AND is_read = 0")
|
||||
->execute([$userId]);
|
||||
json_success(null, 'تم تعليم جميع الإشعارات كمقروءة');
|
||||
} elseif ($id) {
|
||||
$db->prepare("UPDATE notifications SET is_read = 1, read_at = NOW() WHERE id = ? AND user_id = ?")
|
||||
->execute([$id, $userId]);
|
||||
json_success(null, 'تم تعليم الإشعار كمقروء');
|
||||
} else {
|
||||
json_error('يرجى تحديد الإشعار', 422);
|
||||
}
|
||||
Reference in New Issue
Block a user