Files
cal.diy/packages/trpc/server/routers/viewer/teams/createInvite.handler.ts
T
10f965570b feat: Add copy invite link (#8355)
* feat: Add shared invite link

* refactor: Rename Invite to Team Invite model

* feat: add admin check for team invite link procedures

* Replace TeamInvite with VerificationToken

* Add team invite null checks

* Migrates tRPC procedures to new format

* Type fixes

* Update common.json

---------

Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: alannnc <alannnc@gmail.com>
Co-authored-by: Efraín Rochín <roae.85@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
2023-06-06 23:34:14 +00:00

33 lines
874 B
TypeScript

import { randomBytes } from "crypto";
import { isTeamAdmin } from "@calcom/lib/server/queries/teams";
import { prisma } from "@calcom/prisma";
import { TRPCError } from "@calcom/trpc/server";
import type { TrpcSessionUser } from "@calcom/trpc/server/trpc";
import type { TCreateInviteInputSchema } from "./createInvite.schema";
type CreateInviteOptions = {
ctx: {
user: NonNullable<TrpcSessionUser>;
};
input: TCreateInviteInputSchema;
};
export const createInviteHandler = async ({ ctx, input }: CreateInviteOptions) => {
const { teamId } = input;
if (!(await isTeamAdmin(ctx.user.id, teamId))) throw new TRPCError({ code: "UNAUTHORIZED" });
const token = randomBytes(32).toString("hex");
await prisma.verificationToken.create({
data: {
identifier: "",
token,
expires: new Date(),
teamId,
},
});
return token;
};