({
id,
state,
title,
pinned,
accountId,
channelId,
resolutionId,
externalThreadId,
}: UpdateType)
| 90 | } |
| 91 | |
| 92 | static async update({ |
| 93 | id, |
| 94 | state, |
| 95 | title, |
| 96 | pinned, |
| 97 | accountId, |
| 98 | channelId, |
| 99 | resolutionId, |
| 100 | externalThreadId, |
| 101 | }: UpdateType) { |
| 102 | const exist = await prisma.threads.findFirst({ |
| 103 | where: { id, channel: { accountId, id: channelId } }, |
| 104 | }); |
| 105 | if (!exist) { |
| 106 | return null; |
| 107 | } |
| 108 | const thread = await prisma.threads.update({ |
| 109 | include: { |
| 110 | channel: { select: { accountId: true } }, |
| 111 | messages: true, |
| 112 | }, |
| 113 | where: { id }, |
| 114 | data: { |
| 115 | pinned, |
| 116 | ...(title && { title, slug: slugify(title) }), |
| 117 | ...(state && { |
| 118 | state, |
| 119 | closeAt: state === ThreadState.CLOSE ? new Date().getTime() : null, |
| 120 | }), |
| 121 | resolutionId, |
| 122 | externalThreadId, |
| 123 | }, |
| 124 | }); |
| 125 | |
| 126 | if (exist.state !== thread.state) { |
| 127 | if (thread.state === ThreadState.CLOSE) { |
| 128 | await eventThreadClosed({ |
| 129 | accountId: accountId || thread.channel.accountId!, |
| 130 | channelId: thread.channelId, |
| 131 | threadId: id, |
| 132 | }); |
| 133 | } else if (thread.state === ThreadState.OPEN) { |
| 134 | await eventThreadReopened({ |
| 135 | accountId: accountId || thread.channel.accountId!, |
| 136 | channelId: thread.channelId, |
| 137 | threadId: id, |
| 138 | }); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | const serialized = serializeThread(thread); |
| 143 | |
| 144 | await eventThreadUpdated({ |
| 145 | communityId: accountId || thread.channel.accountId!, |
| 146 | channelId: thread.channelId, |
| 147 | messageId: thread.id, |
| 148 | threadId: thread.id, |
| 149 | imitationId: thread.id, |
no test coverage detected