MCPcopy Create free account
hub / github.com/async-labs/async / edit

Method edit

api/server/models/Comment.ts:222–255  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

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) {

Callers 1

addOrEditMethod · 0.95

Calls 2

checkPermissionMethod · 0.95
markdownToHtmlFunction · 0.90

Tested by

no test coverage detected