use team id :/ (#10957)

pull/10964/head
sean-brydon 2023-08-25 17:14:28 +01:00 committed by GitHub
parent 4540c79580
commit 1cd0d7b5ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 27 deletions

View File

@ -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,
};
}