feat: add support for filtering on notification changes

This commit is contained in:
2025-07-29 11:03:04 +05:30
parent bbfb7a4588
commit 63b6cbbc2a
2 changed files with 17 additions and 0 deletions

View File

@@ -112,6 +112,13 @@ export async function listNotifications(
const sortObj = getSortObject(params, notificationFields);
const filterObj = getFilterObject(params) || [];
filterObj.forEach((item) => {
if (item.changes) {
item[`changes.${item.changes.$eq}`] = { $exists: true };
delete item["changes"];
}
});
if (user.role == "client") {
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
}

View File

@@ -37,6 +37,16 @@ export async function getUniqueFields(
const model = modelMap[collection];
if (!model) throw new Error("invalid collection");
if (collection === "notifications" && field === "changes") {
const changeKeys = await model.aggregate([
{ $project: { changesKeys: { $objectToArray: "$changes" } } },
{ $unwind: "$changesKeys" },
{ $group: { _id: "$changesKeys.k" } },
]);
return changeKeys.map((item) => item._id);
}
let values = await model.distinct(field, { tenantId: user.tenantId });
let matchedValues = [];