({ userId, messageId, fileUrl })
| 431 | } |
| 432 | |
| 433 | public static async deleteFile({ userId, messageId, fileUrl }) { |
| 434 | if (!messageId || !fileUrl) { |
| 435 | throw new Error('Bad data'); |
| 436 | } |
| 437 | |
| 438 | const doc = await this.findById(messageId).setOptions({ lean: true }); |
| 439 | |
| 440 | if (!doc) { |
| 441 | throw new Error('Not found'); |
| 442 | } |
| 443 | |
| 444 | await this.checkPermission({ userId, chatId: doc.chatId }); |
| 445 | |
| 446 | await this.findOneAndUpdate( |
| 447 | { _id: messageId }, |
| 448 | { |
| 449 | $pull: { files: { fileUrl } }, |
| 450 | }, |
| 451 | { runValidators: true }, |
| 452 | ); |
| 453 | |
| 454 | const filesToDeleteFromS3 = [fileUrl]; |
| 455 | |
| 456 | deleteFiles(filesToDeleteFromS3).catch((err) => console.log(err)); |
| 457 | } |
| 458 | |
| 459 | public static async addFile({ userId, messageId, fileName, fileUrl }) { |
| 460 | if (!userId || !messageId || !fileName || !fileUrl) { |
nothing calls this directly
no test coverage detected