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

Function create

apps/web/pages/api/merge/index.ts:8–107  ·  view source on GitHub ↗
({
  from,
  to,
  permissions,
  communityId,
}: {
  from: string;
  to: string;
  permissions: PermissionsType;
  communityId: string;
})

Source from the content-addressed store, hash-verified

6import { cors, preflight } from 'utilities/cors';
7
8export async function create({
9 from,
10 to,
11 permissions,
12 communityId,
13}: {
14 from: string;
15 to: string;
16 permissions: PermissionsType;
17 communityId: string;
18}) {
19 if (!from || !to) {
20 return { status: 400 };
21 }
22
23 const community = await CommunityService.find({ communityId });
24
25 if (!community) {
26 return { status: 404 };
27 }
28
29 const thread1 = await prisma.threads.findUnique({
30 where: { id: from },
31 include: {
32 messages: {
33 orderBy: {
34 sentAt: 'asc',
35 },
36 },
37 channel: true,
38 },
39 });
40 const thread2 = await prisma.threads.findUnique({
41 where: { id: to },
42 include: {
43 messages: {
44 orderBy: {
45 sentAt: 'asc',
46 },
47 },
48 channel: true,
49 },
50 });
51 if (!thread1 || !thread2) {
52 return {
53 status: 404,
54 };
55 }
56
57 if (
58 thread1.channel.accountId !== communityId ||
59 thread2.channel.accountId !== communityId
60 ) {
61 return { status: 403 };
62 }
63
64 if (!permissions.user) {
65 return { status: 403 };

Callers 1

handlerFunction · 0.70

Calls 3

mapMethod · 0.80
findMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected