Mọi sự kiện trong app → NotificationService.create() → lưu DB + Pusher realtime → FE hiện toast + badge.
| # | Task | Chi tiết | Status |
|---|---|---|---|
| 01 | Bảng Notification | Đã có trong Prisma. Cần review thêm field: type (enum), actorId, recipientId, targetType, targetId, message, isRead. | done |
| 02 | NotificationService.create() | Method tạo notification: validate → INSERT → Pusher trigger. Cần gọi từ các service khác (Post, Chat, User). | stub |
| 03 | Gọi từ PostService.like() | Sau khi like thành công → notificationService.create({ type: 'LIKE', actorId, recipientId: post.userId }). Không gửi nếu like bài của chính mình. | todo |
| 04 | Gọi từ PostService.reply() | Sau khi reply → notification cho chủ bài gốc. Tương tự cho quote, repost. | todo |
| 05 | Gọi từ mention processing | Khi attachPostMeta xử lý mentions → notification cho mỗi user được @mention. | todo |
| 06 | Gọi từ follow/friend request | Khi follow → notify. Khi gửi friend request → notify. Khi accept → notify. | todo |
| 07 | Gọi từ chat | Tin nhắn mới → notification (nếu user không đang ở conversation đó). Avoid duplicate: không gửi nếu đang online trong chat. | todo |
| 08 | GET /notifications | Danh sách notifications của user. Cursor pagination. Sort mới nhất. Include actor info (name, avatar). | todo |
| 09 | PATCH /notifications/:id/read | Đánh dấu đã đọc 1 notification. Hoặc POST /notifications/read-all đánh dấu tất cả. | todo |
| 10 | GET /notifications/unread-count | Trả số lượng notification chưa đọc. Cache trong Redis, invalidate khi có mới hoặc đọc. | todo |
actorId !== recipientId trước khi tạo.createMany thay vì loop create để giảm DB round-trip.