unique field route for notifications

This commit is contained in:
2025-03-27 16:40:56 +05:30
parent 3e68d594d2
commit fb03e8c265
2 changed files with 58 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import { orgModel } from "../organization/organization.schema";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
import { userModel } from "../user/user.schema";
import { generateId } from "../utils/id";
import {
CreateNotificationInput,
@@ -87,3 +89,29 @@ export async function listNotifications(
},
};
}
export async function getUniqueValuesNotification(
field: string,
tenenatId: string
) {
let values = await notificationModel.distinct(field, { tenantId: tenenatId });
let matchedValues = [];
if (field === "county.name") {
matchedValues = await orgModel.find().where("name").in(values).exec();
} else if (field === "client") {
matchedValues = await orgModel.find().where("_id").in(values).exec();
} else if (field === "assignedTo") {
matchedValues = await userModel.find().where("name").in(values).exec();
}
if (matchedValues.length > 0) {
const newValues = {};
for (const item of matchedValues) {
newValues[item.id] = item.name;
}
return newValues;
}
return values;
}