Files
musadaq-saas/app/modules_app/notifications/read.php
2026-05-08 01:41:28 +03:00

29 lines
854 B
PHP

<?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);
}