(thread: {
channelId: string;
externalThreadId: string;
sentAt: number;
lastReplyAt: number;
slug?: string;
messageCount?: number;
title?: string;
})
| 392 | } |
| 393 | |
| 394 | export const findOrCreateThread = async (thread: { |
| 395 | channelId: string; |
| 396 | externalThreadId: string; |
| 397 | sentAt: number; |
| 398 | lastReplyAt: number; |
| 399 | slug?: string; |
| 400 | messageCount?: number; |
| 401 | title?: string; |
| 402 | }) => { |
| 403 | const exist = await prisma.threads.findUnique({ |
| 404 | where: { |
| 405 | channelId_externalThreadId: { |
| 406 | channelId: thread.channelId, |
| 407 | externalThreadId: thread.externalThreadId, |
| 408 | }, |
| 409 | }, |
| 410 | include: { |
| 411 | messages: true, |
| 412 | }, |
| 413 | }); |
| 414 | if (exist) { |
| 415 | return exist; |
| 416 | } |
| 417 | return await prisma.threads.create({ |
| 418 | data: thread, |
| 419 | include: { |
| 420 | messages: true, |
| 421 | }, |
| 422 | }); |
| 423 | }; |
| 424 | |
| 425 | export async function updateLastReplyAt({ |
| 426 | lastReplyAt, |
no test coverage detected