MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / createInvitation

Function createInvitation

apps/web/services/invites.ts:12–77  ·  view source on GitHub ↗
({
  createdByUserId,
  email: rawEmail,
  accountId,
  host,
  role,
}: {
  createdByUserId: string;
  email: string;
  accountId: string;
  host: string;
  role: Roles;
})

Source from the content-addressed store, hash-verified

10import { eventUserJoin } from './events/eventUserJoin';
11
12export async function createInvitation({
13 createdByUserId,
14 email: rawEmail,
15 accountId,
16 host,
17 role,
18}: {
19 createdByUserId: string;
20 email: string;
21 accountId: string;
22 host: string;
23 role: Roles;
24}) {
25 const email = serializeEmail(rawEmail);
26
27 const exist = await prisma.users.findFirst({
28 where: {
29 account: { id: accountId },
30 auth: { email: email },
31 },
32 });
33
34 if (exist) {
35 return { status: 400, message: 'user already belongs to community' };
36 }
37
38 let invite = await prisma.invites.findFirst({
39 select: {
40 accounts: true,
41 createdBy: { include: { auth: { select: { email: true } } } },
42 },
43 where: {
44 email,
45 accountsId: accountId,
46 },
47 });
48
49 if (!invite) {
50 invite = await prisma.invites.create({
51 select: {
52 accounts: true,
53 createdBy: { include: { auth: { select: { email: true } } } },
54 },
55 data: {
56 email,
57 accountsId: accountId,
58 createdById: createdByUserId,
59 role,
60 },
61 });
62 }
63
64 if (invite.accounts) {
65 await sendInvitationByEmail({
66 email,
67 host,
68 communityName: (invite.accounts.name ||
69 invite.accounts.discordDomain ||

Callers 2

handlerFunction · 0.90
inviteNewMembersFunction · 0.85

Calls 3

serializeEmailFunction · 0.90
sendInvitationByEmailFunction · 0.85
createMethod · 0.45

Tested by

no test coverage detected