2
0

first commit

This commit is contained in:
2024-08-09 00:39:27 +02:00
commit 79688abe2e
5698 changed files with 497838 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { canAccess } from "@calcom/features/ee/sso/lib/saml";
import prisma from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
const userCanCreateTeamGroupMapping = async (
user: NonNullable<TrpcSessionUser>,
organizationId: number | null,
teamId?: number
) => {
if (!organizationId) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Could not find organization id",
});
}
const { message, access } = await canAccess(user, organizationId);
if (!access) {
throw new TRPCError({
code: "BAD_REQUEST",
message,
});
}
if (teamId) {
const orgTeam = await prisma.team.findFirst({
where: {
id: teamId,
parentId: organizationId,
},
select: {
id: true,
},
});
if (!orgTeam) {
throw new TRPCError({
code: "BAD_REQUEST",
message: "Could not find team",
});
}
}
return { organizationId };
};
export default userCanCreateTeamGroupMapping;