| 481 | } |
| 482 | |
| 483 | static async listGroup(domainId: string, uid?: number, names?: string[], search?: string, limit?: number) { |
| 484 | const filter: Filter<GDoc> = { domainId }; |
| 485 | if (typeof uid === 'number') filter.uids = uid; |
| 486 | const $and: Filter<GDoc>[] = []; |
| 487 | if (names?.length) $and.push({ name: { $in: names } }); |
| 488 | if (search) $and.push({ name: { $regex: escapeRegExp(search), $options: 'i' } }); |
| 489 | if ($and.length) filter.$and = $and; |
| 490 | let cursor = collGroup.find(filter); |
| 491 | if (limit) cursor = cursor.limit(limit); |
| 492 | const groups = await cursor.toArray(); |
| 493 | if (uid) { |
| 494 | groups.push({ |
| 495 | _id: new ObjectId(), domainId, uids: [uid], name: uid.toString(), |
| 496 | }); |
| 497 | } |
| 498 | return groups; |
| 499 | } |
| 500 | |
| 501 | static delGroup(domainId: string, name: string) { |
| 502 | deleteUserCache(domainId); |