refactor: getTeamsOfUser function

This commit is contained in:
mirarifhasan
2024-04-29 22:35:40 +06:00
parent 5eed5ce176
commit 20ac35becb

View File

@@ -264,37 +264,25 @@ export class TeamService implements UserDataHandler, OnModuleInit {
} }
async getTeamsOfUser(uid: string, cursor: string | null): Promise<Team[]> { async getTeamsOfUser(uid: string, cursor: string | null): Promise<Team[]> {
if (!cursor) { const entries = await this.prisma.teamMember.findMany({
const entries = await this.prisma.teamMember.findMany({ take: 10,
take: 10, skip: cursor ? 1 : 0,
where: { cursor: cursor
userUid: uid, ? {
}, teamID_userUid: {
include: { teamID: cursor,
team: true, userUid: uid,
}, },
}); }
: undefined,
return entries.map((entry) => entry.team); where: {
} else { userUid: uid,
const entries = await this.prisma.teamMember.findMany({ },
take: 10, include: {
skip: 1, team: true,
cursor: { },
teamID_userUid: { });
teamID: cursor, return entries.map((entry) => entry.team);
userUid: uid,
},
},
where: {
userUid: uid,
},
include: {
team: true,
},
});
return entries.map((entry) => entry.team);
}
} }
async getTeamWithID(teamID: string): Promise<Team | null> { async getTeamWithID(teamID: string): Promise<Team | null> {