From 06b548f12ed853692db78dbbfbe7988382c0fdee Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 11 Jun 2020 19:52:44 +0200 Subject: edit_card start vote better visibility what was voted --- models/cards.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'models') diff --git a/models/cards.js b/models/cards.js index 2e297d63..1ccc836a 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1112,6 +1112,21 @@ Cards.helpers({ return Users.find({ _id: { $in: this.vote.negative } }); return []; }, + voteState() { + const userId = Meteor.userId(); + let state; + if (this.vote) { + if (this.vote.positive) { + state = _.contains(this.vote.positive, userId); + if (state === true) return true; + } + if (this.vote.negative) { + state = _.contains(this.vote.negative, userId); + if (state === true) return false; + } + } + return null; + }, getId() { if (this.isLinked()) { @@ -2374,6 +2389,10 @@ if (Meteor.isServer) { * @param {boolean} [isOverTime] the new isOverTime field of the card * @param {string} [customFields] the new customFields value of the card * @param {string} [color] the new color of the card + * @param {Object} [vote] the vote object + * @param {string} vote.question the vote question + * @param {boolean} vote.public show who voted what + * @param {boolean} vote.allowNonBoardMembers allow all logged in users to vote? * @return_type {_id: string} */ JsonRoutes.add( @@ -2473,6 +2492,24 @@ if (Meteor.isServer) { { $set: { color: newColor } }, ); } + if (req.body.hasOwnProperty('vote')) { + const newVote = req.body.vote; + newVote.positive = []; + newVote.negative = []; + if (!newVote.hasOwnProperty('public')) newVote.public = false; + if (!newVote.hasOwnProperty('allowNonBoardMembers')) + newVote.allowNonBoardMembers = false; + + Cards.direct.update( + { + _id: paramCardId, + listId: paramListId, + boardId: paramBoardId, + archived: false, + }, + { $set: { vote: newVote } }, + ); + } if (req.body.hasOwnProperty('labelIds')) { let newlabelIds = req.body.labelIds; if (_.isString(newlabelIds)) { -- cgit v1.2.3-1-g7c22