mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: group api (#1168)
This commit is contained in:
1 parent
e654a5b7e6
commit
81cf24106b
2 files changed
+15
-13
No files matched your search
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user