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

Method addFile

api/server/models/Comment.ts:364–396  ·  view source on GitHub ↗
({ userId, commentId, fileName, fileUrl })

Source from the content-addressed store, hash-verified

362 }
363
364 public static async addFile({ userId, commentId, fileName, fileUrl }) {
365 if (!userId || !commentId || !fileName || !fileUrl) {
366 throw new Error('Bad data');
367 }
368
369 const doc = await this.findOne({ _id: commentId }).setOptions({ lean: true });
370
371 if (!doc) {
372 throw new Error('Not found');
373 }
374
375 await this.checkPermission({ userId, discussionId: doc.discussionId });
376
377 const commentWithFile = await this.findOneAndUpdate(
378 { _id: commentId },
379 {
380 $push: {
381 files: {
382 fileName,
383 fileUrl,
384 addedAt: new Date(),
385 },
386 },
387 },
388 { runValidators: true, new: true },
389 ).setOptions({
390 lean: true,
391 });
392
393 return commentWithFile.files.find((f) => {
394 return f.fileUrl === fileUrl;
395 });
396 }
397}
398
399mongoSchema.loadClass(CommentClass);

Callers

nothing calls this directly

Calls 1

checkPermissionMethod · 0.95

Tested by

no test coverage detected