Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #296 from pangara/EPIC-1259
Browse files Browse the repository at this point in the history
EPIC-1259 Deleting a document does not update its associated collections
  • Loading branch information
marklise authored Nov 1, 2017
2 parents 64137e3 + 5b95bc8 commit 8c21d95
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions modules/documents/client/directives/documents.manager.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,13 @@ angular.module('documents')
};

self.deleteDocument = function(documentID) {
var collections = null;
return Document.lookup(documentID)
.then( function (doc) {
.then(function(doc) {
collections = doc.collections;
return Document.getProjectDocumentVersions(doc._id);
})
.then( function (docs) {
.then(function(docs) {
// Are there any prior versions? If so, make them the latest and then delete
// otherwise delete
if (docs.length > 0) {
Expand All @@ -407,9 +409,22 @@ angular.module('documents')
return null;
}
})
.then( function () {
// Delete it from the system.
.then(function() {
// EPIC-1259: If there are there any collections associated with this document,
// then delete the collection document reference in the collections as well.
var promises = _.union(_.map(collections, function(c) {
return CollectionModel.removeOtherDocument(c._id, documentID);
}), _.map(collections, function(c) {
return CollectionModel.removeMainDocument(c._id, documentID);
}));
return Promise.all(promises);
})
.then(function () {
// Delete the document from the system.
return Document.deleteDocument(documentID);
})
.catch (function(err) {
AlertService.error('The document could not be deleted.');
});
};

Expand Down

0 comments on commit 8c21d95

Please sign in to comment.