(data)
| 268 | } |
| 269 | |
| 270 | public static async edit(data) { |
| 271 | const { content, userId, id } = data; |
| 272 | |
| 273 | if (!content || !id) { |
| 274 | throw new Error('Bad data'); |
| 275 | } |
| 276 | |
| 277 | const doc = await this.findById(id).setOptions({ lean: true }); |
| 278 | |
| 279 | if (!doc) { |
| 280 | throw new Error('Not found'); |
| 281 | } |
| 282 | |
| 283 | await this.checkPermission({ |
| 284 | userId, |
| 285 | chatId: doc.chatId, |
| 286 | doc, |
| 287 | }); |
| 288 | |
| 289 | const htmlContent = markdownToHtml(content); |
| 290 | |
| 291 | const updatedObj = await this.findOneAndUpdate( |
| 292 | { _id: id }, |
| 293 | { |
| 294 | content, |
| 295 | htmlContent, |
| 296 | isEdited: true, |
| 297 | lastEditedAt: new Date(), |
| 298 | }, |
| 299 | { runValidators: true, new: true }, |
| 300 | ); |
| 301 | |
| 302 | return updatedObj; |
| 303 | } |
| 304 | |
| 305 | public static async deleteForClearHistory({ userId, id }) { |
| 306 | if (!id) { |
no test coverage detected