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

Method edit

api/server/models/Message.ts:270–303  ·  view source on GitHub ↗
(data)

Source from the content-addressed store, hash-verified

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

Callers 1

addOrEditMethod · 0.95

Calls 2

checkPermissionMethod · 0.95
markdownToHtmlFunction · 0.90

Tested by

no test coverage detected