({
params,
}: {
params: {
communityName?: string;
page?: number;
limit?: number;
channelIds?: string[];
};
})
| 16 | } |
| 17 | |
| 18 | export async function index({ |
| 19 | params, |
| 20 | }: { |
| 21 | params: { |
| 22 | communityName?: string; |
| 23 | page?: number; |
| 24 | limit?: number; |
| 25 | channelIds?: string[]; |
| 26 | }; |
| 27 | }) { |
| 28 | const community = await CommunityService.find(params); |
| 29 | if (!community) { |
| 30 | return { status: 404 }; |
| 31 | } |
| 32 | |
| 33 | const page = getPage(params.page); |
| 34 | const channels = await ChannelsService.findPublic(community.id); |
| 35 | |
| 36 | if (!params.limit) { |
| 37 | return { status: 400 }; |
| 38 | } |
| 39 | |
| 40 | const limit = Number(params.limit); |
| 41 | |
| 42 | const condition = { |
| 43 | hidden: false, |
| 44 | messages: { |
| 45 | some: {}, |
| 46 | }, |
| 47 | lastReplyAt: { not: null }, |
| 48 | channelId: { in: channels.map(({ id }) => id) }, |
| 49 | } as any; |
| 50 | |
| 51 | const threads = await prisma.threads.findMany({ |
| 52 | where: condition, |
| 53 | include: { |
| 54 | messages: { |
| 55 | include: { |
| 56 | author: true, |
| 57 | mentions: { |
| 58 | include: { |
| 59 | users: true, |
| 60 | }, |
| 61 | }, |
| 62 | reactions: true, |
| 63 | attachments: true, |
| 64 | }, |
| 65 | orderBy: { sentAt: 'asc' }, |
| 66 | }, |
| 67 | channel: true, |
| 68 | }, |
| 69 | orderBy: { lastReplyAt: 'desc' }, |
| 70 | take: limit, |
| 71 | skip: (page - 1) * limit, |
| 72 | }); |
| 73 | |
| 74 | const total = await prisma.threads.count({ |
| 75 | where: condition, |
nothing calls this directly
no test coverage detected