import { isOrganisationAdmin } from "@calcom/lib/server/queries/organisations"; import { prisma } from "@calcom/prisma"; import { TRPCError } from "@trpc/server"; import type { TrpcSessionUser } from "../../../trpc"; type GetTeamsHandler = { ctx: { user: NonNullable; }; }; export async function getTeamsHandler({ ctx }: GetTeamsHandler) { const currentUser = ctx.user; if (!currentUser.organizationId) throw new TRPCError({ code: "UNAUTHORIZED" }); // check if user is admin of organization if (!(await isOrganisationAdmin(currentUser?.id, currentUser.organizationId))) throw new TRPCError({ code: "UNAUTHORIZED" }); const allOrgTeams = await prisma.team.findMany({ where: { parentId: currentUser.organizationId, }, select: { id: true, name: true, }, }); return allOrgTeams; } export default getTeamsHandler;