units,lesson as standalone

This commit is contained in:
2026-07-10 11:44:46 +08:00
parent 86fba50b95
commit e1ffdab190
46 changed files with 1463 additions and 197 deletions
+25 -3
View File
@@ -23,7 +23,7 @@ async function list(req, res) {
const offset = (page - 1) * limit;
const { count, rows } = await UserNotification.findAndCountAll({
where: { user_id: userId },
where: { user_id: userId, show_in_notifications: true },
order: [['createdAt', 'DESC']],
limit,
offset,
@@ -44,7 +44,7 @@ async function unseenCount(req, res) {
if (!req.user) return R.success(res, 'Unseen count fetched.', { count: null });
try {
const count = await UserNotification.count({
where: { user_id: req.user.user_id, seen: false },
where: { user_id: req.user.user_id, seen: false, show_in_notifications: true },
});
return R.success(res, 'Unseen count fetched.', { count });
} catch (err) {
@@ -53,6 +53,28 @@ async function unseenCount(req, res) {
}
}
// ─── GET /client/notifications/sticky ─────────────────────────────────────
async function stickyAnnouncement(req, res) {
try {
const notification = await UserNotification.findOne({
where: {
user_id: req.user.user_id,
seen: false,
show_in_sticky: true,
type: "announcement",
},
order: [["createdAt", "DESC"]],
});
return R.success(res, "Sticky announcement fetched.", {
announcement: notification,
});
} catch (err) {
console.error("[CLIENT NOTIFICATION] stickyAnnouncement error:", err);
return R.error(res, "Failed to fetch sticky announcement.");
}
}
// ─── PATCH /client/notifications/:id/seen ────────────────────────────────────
async function markSeen(req, res) {
try {
@@ -97,4 +119,4 @@ async function clearAll(req, res) {
}
}
module.exports = { list, unseenCount, markSeen, markAllSeen, clearAll };
module.exports = { list, unseenCount, stickyAnnouncement, markSeen, markAllSeen, clearAll };