Files
calendar/packages/features/ee/dsync/lib/server/userCanCreateTeamGroupMapping.ts
T
Benny JooandGitHub 9855176948 refactor: Remove all TrpcSessionUser usages in @calcom/features (#27853)
* sessionUser in features

* update sessionMiddleware

* update

* format changes

* update import paths

* fix

* fix ts errors

* refactor

* fix

* fix

* fix

* fix

* rename

* rename

* rename

* use error with code objs
2026-02-24 09:29:54 +00:00

40 lines
1019 B
TypeScript

import { canAccessOrganization } from "@calcom/features/ee/sso/lib/saml";
import { ErrorCode } from "@calcom/lib/errorCodes";
import { ErrorWithCode } from "@calcom/lib/errors";
import prisma from "@calcom/prisma";
const userCanCreateTeamGroupMapping = async (
user: { id: number; email: string },
organizationId: number | null,
teamId?: number
) => {
if (!organizationId) {
throw new ErrorWithCode(ErrorCode.BadRequest, "Could not find organization id");
}
const { message, access } = await canAccessOrganization(user, organizationId);
if (!access) {
throw new ErrorWithCode(ErrorCode.BadRequest, message);
}
if (teamId) {
const orgTeam = await prisma.team.findFirst({
where: {
id: teamId,
parentId: organizationId,
},
select: {
id: true,
},
});
if (!orgTeam) {
throw new ErrorWithCode(ErrorCode.BadRequest, "Could not find team");
}
}
return { organizationId };
};
export default userCanCreateTeamGroupMapping;