File size: 1,218 Bytes
05cee1f
24727a3
 
 
 
 
 
 
 
47e2259
24727a3
 
 
 
 
 
05cee1f
 
24727a3
 
 
 
 
 
05cee1f
24727a3
 
 
 
 
 
05cee1f
24727a3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { success, paginated } from '../../lib/response.js'
import { getPagination } from '../../lib/pagination.js'
import * as svc from './notifications.service.js'

export async function list(req, res, next) {
  try {
    const { page, limit } = getPagination(req.query)
    const unreadOnly = req.query.unread === 'true'
    const result = await svc.getUserNotifications(req.user.id, { page, limit, unreadOnly })
    paginated(res, { notifications: result.notifications, page: result.page, totalPages: result.totalPages }, result.total, result.page, limit)
  } catch (err) { next(err) }
}

export async function markRead(req, res, next) {
  try {
    const n = await svc.markAsRead(req.user.id, req.params.id)
    if (!n) return success(res, null, 'الإشعار غير موجود', 404)
    success(res, n)
  } catch (err) { next(err) }
}

export async function markAllRead(req, res, next) {
  try {
    await svc.markAllAsRead(req.user.id)
    success(res, null, 'تم تحديد الكل كمقروء')
  } catch (err) { next(err) }
}

export async function unreadCount(req, res, next) {
  try {
    const count = await svc.getUnreadCount(req.user.id)
    success(res, { count })
  } catch (err) { next(err) }
}