Merge branch 'master' into lib-change

This commit is contained in:
Romulus Tsai 蔡仲明 2020-05-08 10:13:11 +08:00
commit c3458855bd
425 changed files with 15176 additions and 28903 deletions

View file

@ -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