fix: unread count error
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user