Files
cal.diy/packages/trpc/server/routers/viewer/teams/deleteInvite.handler.ts
T
sean-brydonandKeith Williams 3c1297aa72 fix: calcom trpc sessio circle dep (#19893)
* fix trpc session circle dep

* fixes trpc session cirlce dep

* fix relative imports

* fix more imports to use types and not trpc

* fix exports

* Fixed types

---------

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2025-03-19 05:50:22 -03:00

37 lines
1.0 KiB
TypeScript

import { isTeamAdmin } from "@calcom/lib/server/queries/teams";
import { prisma } from "@calcom/prisma";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
import { TRPCError } from "@trpc/server";
import type { TDeleteInviteInputSchema } from "./deleteInvite.schema";
type DeleteInviteOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TDeleteInviteInputSchema;
};
export const deleteInviteHandler = async ({ ctx, input }: DeleteInviteOptions) => {
const { token } = input;
const verificationToken = await prisma.verificationToken.findFirst({
where: {
token: token,
},
select: {
teamId: true,
id: true,
},
});
if (!verificationToken) throw new TRPCError({ code: "NOT_FOUND" });
if (!verificationToken.teamId || !(await isTeamAdmin(ctx.user.id, verificationToken.teamId)))
throw new TRPCError({ code: "UNAUTHORIZED" });
await prisma.verificationToken.delete({ where: { id: verificationToken.id } });
};
export default deleteInviteHandler;