fix: unread count error

This commit is contained in:
2026-01-27 17:34:29 +05:30
parent 7ba1f5ca6a
commit 1499ff9804

View File

@@ -109,16 +109,17 @@ export async function markAsRead(alertId: string, user: AuthenticatedUser) {
} }
export async function markAllRead(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<object> = [ const filters: Array<object> = [
{ recipientType: "user", recipientId: user.userId }, { recipientType: "user", recipientId: user.userId },
]; {
if (user.role == "client")
filters.push({
recipientType: "team", recipientType: "team",
recipientId: { $in: [...user.orgId] }, recipientId: { $in: [...user.orgId] },
}); },
else filters.push({ recipientType: "team" }); ];
const updatedResult = await alertsModel.updateMany( const updatedResult = await alertsModel.updateMany(
{ $or: filters }, { $or: filters },
@@ -129,16 +130,17 @@ export async function markAllRead(user: AuthenticatedUser) {
} }
export async function getUnreadCount(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<object> = [ const filters: Array<object> = [
{ recipientType: "user", recipientId: user.userId }, { recipientType: "user", recipientId: user.userId },
]; {
if (user.role == "client")
filters.push({
recipientType: "team", recipientType: "team",
recipientId: { $in: [...user.orgId] }, recipientId: { $in: [...user.orgId] },
}); },
else filters.push({ recipientType: "team" }); ];
const alerts = await alertsModel.find({ const alerts = await alertsModel.find({
$or: filters, $or: filters,