core: group api (#1168)

This commit is contained in:
Baoshuo authored and GitHub committed 2026-06-14 02:15:37 +08:00
1 parent e654a5b7e6
commit 81cf24106b
2 files changed
+15 -13

No files matched your search

+10 -2
View File
@@ -479,8 +479,16 @@ class UserModel {
]);
}
static async listGroup(domainId: string, uid?: number) {
const groups = await collGroup.find(typeof uid === 'number' ? { domainId, uids: uid } : { domainId }).toArray();
static async listGroup(domainId: string, uid?: number, names?: string[], search?: string, limit?: number) {
const filter: Filter<GDoc> = { domainId };
if (typeof uid === 'number') filter.uids = uid;
const $and: Filter<GDoc>[] = [];
if (names?.length) $and.push({ name: { $in: names } });
if (search) $and.push({ name: { $regex: escapeRegExp(search), $options: 'i' } });
if ($and.length) filter.$and = $and;
let cursor = collGroup.find(filter);
if (limit) cursor = cursor.limit(limit);
const groups = await cursor.toArray();
if (uid) {
groups.push({
_id: new ObjectId(), domainId, uids: [uid], name: uid.toString(),