aboutsummaryrefslogtreecommitdiffstats
path: root/web/lib/services/links.ts
blob: f3ff175738102ffad50cc8f584fb759859d9e9aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { LinkCrawlerQueue } from "@remember/shared/queues";
import prisma from "@remember/db";

export async function bookmarkLink(url: string, userId: string) {
  const link = await prisma.bookmarkedLink.create({
    data: {
      url,
      userId,
    },
  });

  // Enqueue crawling request
  await LinkCrawlerQueue.add("crawl", {
    linkId: link.id,
    url: link.url,
  });

  return link;
}

export async function getLinks(userId: string) {
  return await prisma.bookmarkedLink.findMany({
    where: {
      userId,
    },
    select: {
      id: true,
      url: true,
      createdAt: true,
      details: {
        select: {
          title: true,
          description: true,
          imageUrl: true,
          favicon: true,
        },
      },
    },
  });
}