2
0
Files

27 lines
564 B
TypeScript
Raw Permalink Normal View History

2024-08-09 00:39:27 +02:00
import type { Prisma } from "@prisma/client";
import prisma from "@calcom/prisma";
import { TRPCError } from "@trpc/server";
export async function checkPermissions(args: {
userId: number;
teamId?: number;
role: Prisma.MembershipWhereInput["role"];
}) {
const { teamId, userId, role } = args;
if (!teamId) return;
const team = await prisma.team.findFirst({
where: {
id: teamId,
members: {
some: {
userId,
role,
},
},
},
});
if (!team) throw new TRPCError({ code: "UNAUTHORIZED" });
}