summaryrefslogtreecommitdiffstats
path: root/models/cards.js
diff options
context:
space:
mode:
authorRomulus Tsai 蔡仲明 <urakagi@gmail.com>2020-05-08 10:13:11 +0800
committerRomulus Tsai 蔡仲明 <urakagi@gmail.com>2020-05-08 10:13:11 +0800
commitc3458855bdb52c976ee6689ad5a0d4e92e96f2e3 (patch)
treed9dbbcc3087b5bfc520710b5f5624a3f4e2b78e6 /models/cards.js
parent444848876759173ad80203129250d2f0311f30fc (diff)
parentcfcc73724fcd394150d1b815d0a7a4c466e216b5 (diff)
downloadwekan-c3458855bdb52c976ee6689ad5a0d4e92e96f2e3.tar.gz
wekan-c3458855bdb52c976ee6689ad5a0d4e92e96f2e3.tar.bz2
wekan-c3458855bdb52c976ee6689ad5a0d4e92e96f2e3.zip
Merge branch 'master' into lib-change
Diffstat (limited to 'models/cards.js')
-rw-r--r--models/cards.js132
1 files changed, 132 insertions, 0 deletions
diff --git a/models/cards.js b/models/cards.js
index fac8922c..1236de1a 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -304,6 +304,42 @@ Cards.attachSchema(
optional: true,
defaultValue: '',
},
+ vote: {
+ /**
+ * vote object, see below
+ */
+ type: Object,
+ optional: true,
+ },
+ 'vote.question': {
+ type: String,
+ defaultValue: '',
+ },
+ 'vote.positive': {
+ /**
+ * list of members (user IDs)
+ */
+ type: [String],
+ optional: true,
+ defaultValue: [],
+ },
+ 'vote.negative': {
+ /**
+ * list of members (user IDs)
+ */
+ type: [String],
+ optional: true,
+ defaultValue: [],
+ },
+ 'vote.end': {
+ type: Date,
+ optional: true,
+ defaultValue: null,
+ },
+ 'vote.public': {
+ type: Boolean,
+ defaultValue: false,
+ },
}),
);
@@ -981,6 +1017,50 @@ Cards.helpers({
}
},
+ getVoteQuestion() {
+ if (this.isLinkedCard()) {
+ const card = Cards.findOne({ _id: this.linkedId });
+ if (card && card.vote) return card.vote.question;
+ else return null;
+ } else if (this.isLinkedBoard()) {
+ const board = Boards.findOne({ _id: this.linkedId });
+ if (board && board.vote) return board.vote.question;
+ else return null;
+ } else if (this.vote) {
+ return this.vote.question;
+ } else {
+ return null;
+ }
+ },
+
+ getVotePublic() {
+ if (this.isLinkedCard()) {
+ const card = Cards.findOne({ _id: this.linkedId });
+ if (card && card.vote) return card.vote.public;
+ else return null;
+ } else if (this.isLinkedBoard()) {
+ const board = Boards.findOne({ _id: this.linkedId });
+ if (board && board.vote) return board.vote.public;
+ else return null;
+ } else if (this.vote) {
+ return this.vote.public;
+ } else {
+ return null;
+ }
+ },
+
+ voteMemberPositive() {
+ if (this.vote && this.vote.positive)
+ return Users.find({ _id: { $in: this.vote.positive } });
+ return [];
+ },
+
+ voteMemberNegative() {
+ if (this.vote && this.vote.negative)
+ return Users.find({ _id: { $in: this.vote.negative } });
+ return [];
+ },
+
getId() {
if (this.isLinked()) {
return this.linkedId;
@@ -1397,6 +1477,58 @@ Cards.mutations({
},
};
},
+ setVoteQuestion(question, publicVote) {
+ return {
+ $set: {
+ vote: {
+ question,
+ public: publicVote,
+ positive: [],
+ negative: [],
+ },
+ },
+ };
+ },
+ unsetVote() {
+ return {
+ $unset: {
+ vote: '',
+ },
+ };
+ },
+ setVote(userId, forIt) {
+ switch (forIt) {
+ case true:
+ // vote for it
+ return {
+ $pull: {
+ 'vote.negative': userId,
+ },
+ $addToSet: {
+ 'vote.positive': userId,
+ },
+ };
+ case false:
+ // vote against
+ return {
+ $pull: {
+ 'vote.positive': userId,
+ },
+ $addToSet: {
+ 'vote.negative': userId,
+ },
+ };
+
+ default:
+ // Remove votes
+ return {
+ $pull: {
+ 'vote.positive': userId,
+ 'vote.negative': userId,
+ },
+ };
+ }
+ },
});
//FUNCTIONS FOR creation of Activities