feat: custom unique values for taggedUsers field, set the latest taggedUser to assigendTo field

This commit is contained in:
2025-09-01 18:45:42 +05:30
parent 1bc51d98ec
commit 19ab12aab6
2 changed files with 16 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import { orgModel } from "./organization/organization.schema";
import { userModel } from "./user/user.schema";
import { AuthenticatedUser } from "./auth";
import { modelMap } from "./utils/tags";
import { listUsers } from "./user/user.service";
type Collection =
| "users"
@@ -32,6 +33,17 @@ export async function getUniqueFields(
return changeKeys.map((item) => item._id);
}
if (field === "taggedUsers") {
const users = await listUsers(user);
const usersObj = {};
for (const user of users) {
usersObj[user.id] = user.name;
}
return usersObj;
}
let values = await model.distinct(field, { tenantId: user.tenantId });
let matchedValues = [];