MCPcopy Index your code
hub / github.com/Linen-dev/linen.dev / createThreadsOneByDay

Function createThreadsOneByDay

apps/web/bin/factory/threads.ts:16–70  ·  view source on GitHub ↗
(
  channel: channels,
  account: accounts,
  threadsCount: number
)

Source from the content-addressed store, hash-verified

14 * @returns array of threads
15 */
16export async function createThreadsOneByDay(
17 channel: channels,
18 account: accounts,
19 threadsCount: number
20) {
21 const user = await prisma.users.create({
22 data: {
23 isAdmin: true,
24 isBot: false,
25 accountsId: account.id,
26 },
27 });
28
29 const oneDay = 24 * 60 * 60 * 1000;
30 const oneMinute = 1 * 60 * 1000;
31 const nDays = threadsCount * oneDay;
32 const date = new Date().getTime() - nDays;
33
34 const threads = [];
35 for (let i = 0; i < threadsCount; i++) {
36 const thread = await prisma.threads.create({
37 data: {
38 channelId: channel.id,
39 slug: `slug-${channel.channelName}-${channel.id}-${i}`,
40 messageCount: 2,
41 externalThreadId: `thread-ts-${random()}`,
42 sentAt: date + i * oneDay,
43 lastReplyAt: date + i * oneDay,
44 },
45 });
46 await prisma.messages.create({
47 data: {
48 body: `foo-${i}-${random()}`,
49 channelId: channel.id,
50 threadId: thread.id,
51 usersId: user.id,
52 sentAt: new Date(date + i * oneDay).toISOString(),
53 messageFormat: MessageFormat.LINEN,
54 },
55 });
56 await prisma.messages.create({
57 data: {
58 body: `foo-${i}-${random()}`,
59 channelId: channel.id,
60 threadId: thread.id,
61 usersId: user.id,
62 sentAt: new Date(date + i * oneDay + oneMinute).toISOString(),
63 messageFormat: MessageFormat.LINEN,
64 },
65 });
66 threads.push(thread);
67 }
68 await buildPages(account);
69 return threads;
70}

Callers 3

threads.test.tsFile · 0.90
channels.test.tsFile · 0.90
topics.test.tsFile · 0.90

Calls 3

buildPagesFunction · 0.90
randomFunction · 0.50
createMethod · 0.45

Tested by

no test coverage detected