diff options
Diffstat (limited to 'models/cards.js')
-rw-r--r-- | models/cards.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js index 4b18b8f3..de868dde 100644 --- a/models/cards.js +++ b/models/cards.js @@ -406,6 +406,18 @@ Cards.helpers({ return this.isImportedCard() || this.isImportedBoard(); }, + setDescription(description) { + if (this.isImportedCard()) { + const card = Cards.findOne({_id: this.importedId}); + return Cards.update({_id: this.importedId}, {$set: {description}}); + } else if (this.isImportedBoard()) { + const board = Boards.findOne({_id: this.importedId}); + return Boards.update({_id: this.importedId}, {$set: {description}}); + } else { + return {$set: {description}}; + } + }, + getDescription() { if (this.isImportedCard()) { const card = Cards.findOne({_id: this.importedId}); @@ -426,6 +438,62 @@ Cards.helpers({ return null; } }, + + getMembers() { + if (this.isImportedCard()) { + const card = Cards.findOne({_id: this.importedId}); + return card.members; + } else if (this.isImportedBoard()) { + const board = Boards.findOne({_id: this.importedId}); + return board.activeMembers().map((member) => { + return member.userId; + }); + } else { + return this.members; + } + }, + + assignMember(memberId) { + if (this.isImportedCard()) { + return Cards.update( + { _id: this.importedId }, + { $addToSet: { members: memberId }} + ); + } else if (this.isImportedBoard()) { + const board = Boards.findOne({_id: this.importedId}); + return board.addMember(memberId); + } else { + return Cards.update( + { _id: this._id }, + { $addToSet: { members: memberId}} + ); + } + }, + + unassignMember(memberId) { + if (this.isImportedCard()) { + return Cards.update( + { _id: this.importedId }, + { $pull: { members: memberId }} + ); + } else if (this.isImportedBoard()) { + const board = Boards.findOne({_id: this.importedId}); + return board.removeMember(memberId); + } else { + return Cards.update( + { _id: this._id }, + { $pull: { members: memberId}} + ); + } + }, + + toggleMember(memberId) { + if (this.getMembers() && this.getMembers().indexOf(memberId) > -1) { + return this.unassignMember(memberId); + } else { + return this.assignMember(memberId); + } + }, }); Cards.mutations({ |