summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGhassen Rjab <rjab.ghassen@gmail.com>2017-08-31 06:58:02 +0100
committerGhassen Rjab <rjab.ghassen@gmail.com>2017-08-31 06:58:02 +0100
commitee938c04232ab9ac42195a35d38cb7ae11b14d48 (patch)
treef978a306dba8d3c01f0bb4df72deb5c66da42a1c
parentddc21046b9385ac5ce5bbb9a773484fcd056d10c (diff)
downloadwekan-ee938c04232ab9ac42195a35d38cb7ae11b14d48.tar.gz
wekan-ee938c04232ab9ac42195a35d38cb7ae11b14d48.tar.bz2
wekan-ee938c04232ab9ac42195a35d38cb7ae11b14d48.zip
Delete activity related to checklist item when the item is deleted
-rw-r--r--models/checklists.js25
1 files changed, 17 insertions, 8 deletions
diff --git a/models/checklists.js b/models/checklists.js
index ab4fe61d..59682720 100644
--- a/models/checklists.js
+++ b/models/checklists.js
@@ -164,14 +164,23 @@ if (Meteor.isServer) {
// The future is now
Checklists.after.update((userId, doc, fieldNames, modifier) => {
if (fieldNames.includes('items')) {
- Activities.insert({
- userId,
- activityType: 'addChecklistItem',
- cardId: doc.cardId,
- boardId: Cards.findOne(doc.cardId).boardId,
- checklistId: doc._id,
- checklistItemId: modifier.$addToSet.items._id,
- });
+ if (modifier.$addToSet) {
+ Activities.insert({
+ userId,
+ activityType: 'addChecklistItem',
+ cardId: doc.cardId,
+ boardId: Cards.findOne(doc.cardId).boardId,
+ checklistId: doc._id,
+ checklistItemId: modifier.$addToSet.items._id,
+ });
+ } else if (modifier.$pull) {
+ const activity = Activities.findOne({
+ checklistItemId: modifier.$pull.items._id,
+ });
+ if (activity) {
+ Activities.remove(activity._id);
+ }
+ }
}
});