feat: add tagging alerts and sorting on tags
This commit is contained in:
@@ -72,10 +72,30 @@ export async function listPermits(
|
||||
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 permitsList = await permitModel.aggregate([
|
||||
{
|
||||
$match: { $and: [{ tenantId: user.tenantId }, ...filterObj] },
|
||||
},
|
||||
...taggedFilter,
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
@@ -206,6 +226,7 @@ export async function updatePermit(
|
||||
content: msg,
|
||||
},
|
||||
permitId,
|
||||
"permits",
|
||||
user
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user