use team id :/ (#10957)
parent
4540c79580
commit
1cd0d7b5ca
|
@ -1,5 +1,3 @@
|
|||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import type { Dayjs } from "@calcom/dayjs";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import type { DateRange } from "@calcom/lib/date-ranges";
|
||||
|
@ -29,22 +27,11 @@ async function getTeamMembers({
|
|||
cursor: number | null | undefined;
|
||||
limit: number;
|
||||
}) {
|
||||
let whereQuery: Prisma.MembershipWhereInput = {
|
||||
teamId,
|
||||
};
|
||||
|
||||
if (teamIds) {
|
||||
whereQuery = {
|
||||
teamId: {
|
||||
in: teamIds,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return await prisma.membership.findMany({
|
||||
where: {
|
||||
...whereQuery,
|
||||
accepted: true,
|
||||
teamId: {
|
||||
in: teamId ? [teamId] : teamIds,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
@ -116,23 +103,15 @@ async function getInfoForAllTeams({ ctx, input }: GetOptions) {
|
|||
},
|
||||
select: {
|
||||
id: true,
|
||||
teamId: true,
|
||||
},
|
||||
})
|
||||
.then((memberships) => memberships.map((membership) => membership.id));
|
||||
.then((memberships) => memberships.map((membership) => membership.teamId));
|
||||
|
||||
if (!teamIds.length) {
|
||||
throw new TRPCError({ code: "NOT_FOUND", message: "User is not part of any organization or team." });
|
||||
}
|
||||
|
||||
const getTotalMembers = await prisma.$queryRaw<{
|
||||
count: number;
|
||||
}>(Prisma.sql`
|
||||
SELECT
|
||||
COUNT(DISTINCT "userId") as "count"
|
||||
FROM "Membership"
|
||||
WHERE "teamId" IN (${Prisma.join(teamIds)})
|
||||
`);
|
||||
|
||||
const teamMembers = await getTeamMembers({
|
||||
teamIds,
|
||||
cursor,
|
||||
|
@ -141,7 +120,7 @@ async function getInfoForAllTeams({ ctx, input }: GetOptions) {
|
|||
|
||||
return {
|
||||
teamMembers,
|
||||
totalTeamMembers: getTotalMembers.count,
|
||||
totalTeamMembers: teamMembers.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue