({
messageId,
threadId,
}: {
messageId: string;
threadId: string;
})
| 35 | |
| 36 | class ThreadsServices { |
| 37 | static async updateMetrics({ |
| 38 | messageId, |
| 39 | threadId, |
| 40 | }: { |
| 41 | messageId: string; |
| 42 | threadId: string; |
| 43 | }) { |
| 44 | const thread = await prisma.threads.findUnique({ |
| 45 | select: { firstManagerReplyAt: true, firstUserReplyAt: true }, |
| 46 | where: { id: threadId }, |
| 47 | }); |
| 48 | |
| 49 | if (areRepliesAtFilled(thread)) { |
| 50 | return Promise.resolve('nothing to update, already updated'); |
| 51 | } else { |
| 52 | const [firstMessage, lastMessage] = await getFirstAndLastMessages( |
| 53 | threadId, |
| 54 | messageId |
| 55 | ); |
| 56 | if (areAuthorSameAsReplier(firstMessage, lastMessage)) { |
| 57 | return Promise.resolve('nothing to update, same author'); |
| 58 | } |
| 59 | if (lastMessage && isReplierManager(thread, lastMessage)) { |
| 60 | await updateThreadMetrics(threadId, lastMessage, 'firstManagerReplyAt'); |
| 61 | return Promise.resolve('done, firstManagerReplyAt'); |
| 62 | } |
| 63 | if (lastMessage && isReplierMember(thread, lastMessage)) { |
| 64 | await updateThreadMetrics(threadId, lastMessage, 'firstUserReplyAt'); |
| 65 | return Promise.resolve('done, firstUserReplyAt'); |
| 66 | } |
| 67 | } |
| 68 | return Promise.resolve('nothing to update'); |
| 69 | } |
| 70 | |
| 71 | static async find({ channelId, cursor, accountId }: FindType) { |
| 72 | const channel = await prisma.channels.findFirst({ |
no test coverage detected