2023-04-25 22:39:47 +00:00
|
|
|
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
|
|
|
import { getTeamWithMembers } from "@calcom/lib/server/queries/teams";
|
2023-05-02 11:44:05 +00:00
|
|
|
import type { MembershipRole } from "@calcom/prisma/enums";
|
2023-04-25 22:39:47 +00:00
|
|
|
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
|
|
import type { TGetInputSchema } from "./get.schema";
|
|
|
|
|
|
|
|
type GetOptions = {
|
|
|
|
ctx: {
|
|
|
|
user: NonNullable<TrpcSessionUser>;
|
|
|
|
};
|
|
|
|
input: TGetInputSchema;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getHandler = async ({ ctx, input }: GetOptions) => {
|
2023-08-18 21:10:17 +00:00
|
|
|
const team = await getTeamWithMembers({
|
|
|
|
id: input.teamId,
|
|
|
|
userId: ctx.user.organization?.isOrgAdmin ? undefined : ctx.user.id,
|
|
|
|
});
|
2023-04-25 22:39:47 +00:00
|
|
|
|
|
|
|
if (!team) {
|
|
|
|
throw new TRPCError({ code: "NOT_FOUND", message: "Team not found." });
|
|
|
|
}
|
|
|
|
|
|
|
|
const membership = team?.members.find((membership) => membership.id === ctx.user.id);
|
|
|
|
|
|
|
|
return {
|
|
|
|
...team,
|
|
|
|
safeBio: markdownToSafeHTML(team.bio),
|
|
|
|
membership: {
|
|
|
|
role: membership?.role as MembershipRole,
|
|
|
|
accepted: membership?.accepted,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|