Skip to content

Commit

Permalink
fix1
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwhite committed Jul 2, 2024
1 parent c1288c0 commit 313a5de
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions server/src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,47 +81,40 @@ export class GroupService {
async findGroupsByAppidAndUid(appid: string, uid: ObjectId) {
const res = await this.db
.collection<GroupApplication>('GroupApplication')
.aggregate([
{ $match: { appid } },
{
$lookup: {
from: "Group",
localField: "groupId",
foreignField: "_id",
as: "group",
},
},
{ $unwind: "$group" },
{
$lookup: {
from: "GroupMember",
let: { groupId: "$groupId" },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ["$groupId", "$$groupId"] },
{ $eq: ["$uid", uid] },
],
},
},
.aggregate()
.match({ appid })
.lookup({
from: 'Group',
localField: 'groupId',
foreignField: '_id',
as: 'group',
})
.unwind('$group')
.lookup({
from: 'GroupMember',
let: { groupId: '$groupId' },
pipeline: [
{
$match: {
$expr: {
$and: [
{ $eq: ['$groupId', '$$groupId'] },
{ $eq: ['$uid', 'uid'] },
],
},
],
as: "member",
},
},
{ $unwind: "$member" },
{
$project: {
_id: "$group._id",
name: "$group.name",
createdAt: "$group.createdAt",
updatedAt: "$group.updatedAt",
role: "$member.role",
},
},
},
])
],
as: 'member',
})
.unwind('$member')
.project({
_id: '$group._id',
name: '$group.name',
createdAt: '$group.createdAt',
updatedAt: '$group.updatedAt',
role: '$member.role',
})
.toArray()

return res
Expand Down

0 comments on commit 313a5de

Please sign in to comment.