feat: add tagging alerts and sorting on tags
This commit is contained in:
@@ -77,6 +77,7 @@ export async function updateNotification(
|
||||
content: msg,
|
||||
},
|
||||
notifId,
|
||||
"notifications",
|
||||
user
|
||||
);
|
||||
|
||||
@@ -84,6 +85,7 @@ export async function updateNotification(
|
||||
await createNote(
|
||||
{ content: msg },
|
||||
updateNotificationResult.permitId,
|
||||
"notifications",
|
||||
user
|
||||
);
|
||||
|
||||
@@ -123,6 +125,25 @@ export async function listNotifications(
|
||||
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
|
||||
}
|
||||
|
||||
let taggedFilter = [];
|
||||
if (sortObj.taggedUsers) {
|
||||
taggedFilter = [
|
||||
{
|
||||
$addFields: {
|
||||
taggedUsers: {
|
||||
$filter: {
|
||||
input: "$taggedUsers",
|
||||
as: "user",
|
||||
cond: { $eq: ["$$user.userId", user.userId] },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{ $match: { "taggedUsers.0": { $exists: true } } },
|
||||
{ $sort: { "taggedUsers.taggedAt": sortObj.taggedUsers } },
|
||||
];
|
||||
}
|
||||
|
||||
const pipeline: any = [
|
||||
{
|
||||
$match: { $and: [{ tenantId: user.tenantId }, ...filterObj] },
|
||||
@@ -140,6 +161,7 @@ export async function listNotifications(
|
||||
|
||||
pipeline.push(
|
||||
...[
|
||||
...taggedFilter,
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
|
||||
Reference in New Issue
Block a user