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

Method findWithStats

apps/web/services/channels/index.ts:78–112  ·  view source on GitHub ↗
(
    communityId: string
  )

Source from the content-addressed store, hash-verified

76 }
77
78 static async findWithStats(
79 communityId: string
80 ): Promise<findChannelsWithStats> {
81 return await prisma.channels
82 .findMany({
83 include: {
84 _count: { select: { threads: true } },
85 threads: {
86 take: 1,
87 orderBy: { sentAt: 'desc' },
88 select: { sentAt: true },
89 },
90 },
91 where: {
92 accountId: communityId,
93 type: { not: ChannelType.DM },
94 },
95 })
96 .then((channels) =>
97 channels.map(({ threads, _count, ...rest }) => {
98 const lastThreadAt = threads.find(Boolean)?.sentAt;
99 const threadCount = _count.threads;
100
101 let stats = `${threadCount} thread${threadCount > 1 ? 's' : ''}`;
102
103 if (lastThreadAt) {
104 const date = new Date(
105 Math.floor(Number(lastThreadAt))
106 ).toISOString();
107 stats += `, latest from ${formatDistance(date)}`;
108 }
109 return { ...serializeChannel(rest), stats };
110 })
111 );
112 }
113
114 static async setDefaultChannels({
115 channelIds,

Callers 1

index.tsFile · 0.80

Calls 4

formatDistanceFunction · 0.90
serializeChannelFunction · 0.90
mapMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected