(data)
| 220 | } |
| 221 | |
| 222 | public static async edit(data) { |
| 223 | const { content, userId, id } = data; |
| 224 | |
| 225 | if (!content || !id) { |
| 226 | throw new Error('Bad data'); |
| 227 | } |
| 228 | |
| 229 | const doc = await this.findById(id).setOptions({ lean: true }); |
| 230 | |
| 231 | if (!doc) { |
| 232 | throw new Error('Not found'); |
| 233 | } |
| 234 | |
| 235 | await this.checkPermission({ |
| 236 | userId, |
| 237 | discussionId: doc.discussionId, |
| 238 | doc, |
| 239 | }); |
| 240 | |
| 241 | const htmlContent = markdownToHtml(content); |
| 242 | |
| 243 | const updatedObj = await this.findOneAndUpdate( |
| 244 | { _id: id }, |
| 245 | { |
| 246 | content, |
| 247 | htmlContent, |
| 248 | isEdited: true, |
| 249 | lastEditedAt: new Date(), |
| 250 | }, |
| 251 | { runValidators: true, new: true }, |
| 252 | ); |
| 253 | |
| 254 | return updatedObj; |
| 255 | } |
| 256 | |
| 257 | public static async delete({ userId, id, isDiscussionBeingDeleted }) { |
| 258 | if (!id) { |
no test coverage detected