From 1499ff980401a21582484da1cd086099eb623488 Mon Sep 17 00:00:00 2001 From: Akhil Meka Date: Tue, 27 Jan 2026 17:34:29 +0530 Subject: [PATCH] fix: unread count error --- src/alert/alert.service.ts | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/alert/alert.service.ts b/src/alert/alert.service.ts index 65fbd02..de26eb5 100644 --- a/src/alert/alert.service.ts +++ b/src/alert/alert.service.ts @@ -109,16 +109,17 @@ export async function markAsRead(alertId: string, user: AuthenticatedUser) { } export async function markAllRead(user: AuthenticatedUser) { + if (["superAdmin", "admin", "team"].includes(user.role)) { + user.orgId.push(process.env.SUNCOAST_ID); + } + const filters: Array = [ { recipientType: "user", recipientId: user.userId }, - ]; - - if (user.role == "client") - filters.push({ + { recipientType: "team", recipientId: { $in: [...user.orgId] }, - }); - else filters.push({ recipientType: "team" }); + }, + ]; const updatedResult = await alertsModel.updateMany( { $or: filters }, @@ -129,16 +130,17 @@ export async function markAllRead(user: AuthenticatedUser) { } export async function getUnreadCount(user: AuthenticatedUser) { + if (["superAdmin", "admin", "team"].includes(user.role)) { + user.orgId.push(process.env.SUNCOAST_ID); + } + const filters: Array = [ { recipientType: "user", recipientId: user.userId }, - ]; - - if (user.role == "client") - filters.push({ + { recipientType: "team", recipientId: { $in: [...user.orgId] }, - }); - else filters.push({ recipientType: "team" }); + }, + ]; const alerts = await alertsModel.find({ $or: filters,