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

Method deleteFile

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

Source from the content-addressed store, hash-verified

295 }
296
297 public static async deleteFile({ userId, commentId, fileUrl }) {
298 if (!commentId || !fileUrl) {
299 throw new Error('Bad data');
300 }
301
302 const doc = await this.findById(commentId).setOptions({ lean: true });
303
304 if (!doc) {
305 throw new Error('Not found');
306 }
307
308 await this.checkPermission({ userId, discussionId: doc.discussionId });
309
310 await this.findOneAndUpdate(
311 { _id: commentId },
312 {
313 $pull: { files: { fileUrl } },
314 },
315 { runValidators: true },
316 );
317
318 const filesToDeleteFromS3 = [fileUrl];
319
320 deleteFiles(filesToDeleteFromS3).catch((err) => console.log(err));
321 }
322
323 private static async checkPermission({ userId, discussionId, doc = null }) {
324 if (!userId || !discussionId) {

Callers

nothing calls this directly

Calls 2

checkPermissionMethod · 0.95
deleteFilesFunction · 0.90

Tested by

no test coverage detected