From be1517facd982e017e52679afe2524b50c7bdf98 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:42:49 +0100 Subject: [PATCH] fix: get correct count for team members in slider (#12017) --- .../availability/team/listTeamAvailability.handler.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/trpc/server/routers/viewer/availability/team/listTeamAvailability.handler.ts b/packages/trpc/server/routers/viewer/availability/team/listTeamAvailability.handler.ts index f495e8d047..3213573854 100644 --- a/packages/trpc/server/routers/viewer/availability/team/listTeamAvailability.handler.ts +++ b/packages/trpc/server/routers/viewer/availability/team/listTeamAvailability.handler.ts @@ -1,3 +1,5 @@ +import { Prisma } from "@prisma/client"; + import type { Dayjs } from "@calcom/dayjs"; import dayjs from "@calcom/dayjs"; import type { DateRange } from "@calcom/lib/date-ranges"; @@ -120,9 +122,16 @@ async function getInfoForAllTeams({ ctx, input }: GetOptions) { limit, }); + // Get total team count across all teams the user is in (for pagination) + + const totalTeamMembers = + await prisma.$queryRaw`SELECT COUNT(DISTINCT "userId")::integer from "Membership" WHERE "teamId" IN (${Prisma.join( + teamIds + )})`; + return { teamMembers, - totalTeamMembers: teamMembers.length, + totalTeamMembers, }; }