(
communityId: string
)
| 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, |
no test coverage detected