|
|
@@ -43,17 +43,31 @@ class AttachmentService {
|
|
|
return attachment;
|
|
|
}
|
|
|
|
|
|
- async removeAttachment(attachments) {
|
|
|
+ async removeAllAttachment(attachments) {
|
|
|
const { fileUploadService } = this.crowi;
|
|
|
const attachmentsCollection = mongoose.connection.collection('attachments');
|
|
|
const unorderAttachmentsBulkOp = attachmentsCollection.initializeUnorderedBulkOp();
|
|
|
|
|
|
- fileUploadService.deleteFiles(attachments);
|
|
|
- attachments.forEach((attachment) => {
|
|
|
- // fileUploadService.deleteFiles(attachment);
|
|
|
- unorderAttachmentsBulkOp.find({ _id: attachment._id }).remove();
|
|
|
- });
|
|
|
- await unorderAttachmentsBulkOp.execute();
|
|
|
+ if (attachments.length > 1) {
|
|
|
+ fileUploadService.deleteFiles(attachments);
|
|
|
+
|
|
|
+ attachments.forEach((attachment) => {
|
|
|
+ unorderAttachmentsBulkOp.find({ _id: attachment._id }).remove();
|
|
|
+ });
|
|
|
+ await unorderAttachmentsBulkOp.execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ async removeAttachment(attachmentId) {
|
|
|
+ const Attachment = this.crowi.model('Attachment');
|
|
|
+ const { fileUploadService } = this.crowi;
|
|
|
+ const attachment = await Attachment.findById(attachmentId);
|
|
|
+
|
|
|
+ await fileUploadService.deleteFile(attachment);
|
|
|
+ await attachment.remove();
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|