Files
calendar/packages/app-store/routing-forms/trpc/getAttributesForTeam.handler.ts
T

33 lines
949 B
TypeScript

import { MembershipRepository } from "@calcom/lib/server/repository/membership";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import { TRPCError } from "@trpc/server";
import { getAttributesForTeam } from "../lib/getAttributes";
import type { TGetAttributesForTeamInputSchema } from "./getAttributesForTeam.schema";
type GetAttributesForTeamHandlerOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TGetAttributesForTeamInputSchema;
};
export default async function getAttributesForTeamHandler({
ctx,
input,
}: GetAttributesForTeamHandlerOptions) {
const { teamId } = input;
const { user } = ctx;
const isMemberOfTeam = await MembershipRepository.findFirstByUserIdAndTeamId({ userId: user.id, teamId });
if (!isMemberOfTeam) {
throw new TRPCError({
code: "NOT_FOUND",
message: "You are not a member of this team",
});
}
return getAttributesForTeam({ teamId });
}