({
channelIds,
sentAt,
sort = 'desc',
limit = PAGE_SIZE,
direction,
anonymizeUsers = false,
anonymize,
page,
}: {
channelIds: string[];
limit?: number;
anonymizeUsers?: boolean;
anonymize: AnonymizeType;
page?: number;
} & FindThreadsByCursorType)
| 309 | export default ThreadsServices; |
| 310 | |
| 311 | export async function findThreadsByCursor({ |
| 312 | channelIds, |
| 313 | sentAt, |
| 314 | sort = 'desc', |
| 315 | limit = PAGE_SIZE, |
| 316 | direction, |
| 317 | anonymizeUsers = false, |
| 318 | anonymize, |
| 319 | page, |
| 320 | }: { |
| 321 | channelIds: string[]; |
| 322 | limit?: number; |
| 323 | anonymizeUsers?: boolean; |
| 324 | anonymize: AnonymizeType; |
| 325 | page?: number; |
| 326 | } & FindThreadsByCursorType): Promise<ThreadsWithMessagesFull[]> { |
| 327 | if (!channelIds.length) { |
| 328 | return []; |
| 329 | } |
| 330 | |
| 331 | const threads = await prisma.threads.findMany({ |
| 332 | take: limit, |
| 333 | where: { |
| 334 | ...(!!sentAt && |
| 335 | !!direction && { sentAt: { [direction]: BigInt(sentAt) } }), |
| 336 | ...(!!page && { page }), |
| 337 | channelId: { |
| 338 | in: channelIds, |
| 339 | }, |
| 340 | hidden: false, |
| 341 | messageCount: { |
| 342 | gte: 1, |
| 343 | }, |
| 344 | }, |
| 345 | include: { |
| 346 | messages: { |
| 347 | include: { |
| 348 | author: true, |
| 349 | mentions: { |
| 350 | include: { |
| 351 | users: true, |
| 352 | }, |
| 353 | }, |
| 354 | reactions: true, |
| 355 | attachments: true, |
| 356 | }, |
| 357 | orderBy: { sentAt: 'asc' }, |
| 358 | }, |
| 359 | channel: true, |
| 360 | }, |
| 361 | ...(!!sort && { orderBy: { sentAt: sort } }), |
| 362 | }); |
| 363 | return ( |
| 364 | anonymizeUsers |
| 365 | ? threads.map((thread) => |
| 366 | anonymizeMessages(thread, anonymize as AnonymizeType) |
| 367 | ) |
| 368 | : threads |
no test coverage detected