From 8137f2692fe3e1d9f1c0a9b635ef15cdf36728f7 Mon Sep 17 00:00:00 2001 From: guillaume Date: Tue, 23 Apr 2019 18:00:09 +0200 Subject: remove feature --- models/swimlanes.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'models/swimlanes.js') diff --git a/models/swimlanes.js b/models/swimlanes.js index 9da4afb5..bd2565af 100644 --- a/models/swimlanes.js +++ b/models/swimlanes.js @@ -180,6 +180,10 @@ Swimlanes.helpers({ const user = Users.findOne(Meteor.userId()); return user.profile.boardTemplatesSwimlaneId === this._id; }, + + remove() { + Swimlanes.remove({ _id: this._id}); + }, }); Swimlanes.mutations({ @@ -234,7 +238,21 @@ if (Meteor.isServer) { }); }); - Swimlanes.before.remove((userId, doc) => { + Swimlanes.before.remove(function(userId, doc) { + const lists = Lists.find({ + boardId: doc.boardId, + swimlaneId: {$in: [doc._id, '']}, + archived: false, + }, { sort: ['sort'] }); + + if (lists.count() < 2) { + lists.forEach((list) => { + list.remove(); + }); + } else { + Cards.remove({swimlaneId: doc._id}); + } + Activities.insert({ userId, type: 'swimlane', -- cgit v1.2.3-1-g7c22