feat: add support for filtering on notification changes
This commit is contained in:
@@ -112,6 +112,13 @@ export async function listNotifications(
|
|||||||
const sortObj = getSortObject(params, notificationFields);
|
const sortObj = getSortObject(params, notificationFields);
|
||||||
const filterObj = getFilterObject(params) || [];
|
const filterObj = getFilterObject(params) || [];
|
||||||
|
|
||||||
|
filterObj.forEach((item) => {
|
||||||
|
if (item.changes) {
|
||||||
|
item[`changes.${item.changes.$eq}`] = { $exists: true };
|
||||||
|
delete item["changes"];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (user.role == "client") {
|
if (user.role == "client") {
|
||||||
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
|
filterObj.push({ client: new mongoose.Types.ObjectId(user.orgId) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,16 @@ export async function getUniqueFields(
|
|||||||
const model = modelMap[collection];
|
const model = modelMap[collection];
|
||||||
if (!model) throw new Error("invalid 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 values = await model.distinct(field, { tenantId: user.tenantId });
|
||||||
|
|
||||||
let matchedValues = [];
|
let matchedValues = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user