2016-10-21 21:21:09 +08:00
|
|
|
import Polls from '/imports/api/polls';
|
|
|
|
import { check } from 'meteor/check';
|
2016-10-22 01:11:28 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2016-10-21 21:21:09 +08:00
|
|
|
|
2016-10-22 01:42:43 +08:00
|
|
|
export default function updateVotes(poll, meetingId, requesterId) {
|
2016-10-21 21:21:09 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterId, String);
|
|
|
|
check(poll, Object);
|
|
|
|
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
answers,
|
|
|
|
} = poll;
|
|
|
|
|
|
|
|
const numResponders = poll.num_responders;
|
|
|
|
const numRespondents = poll.num_respondents;
|
|
|
|
|
|
|
|
check(id, String);
|
|
|
|
check(answers, Array);
|
|
|
|
|
|
|
|
check(numResponders, Number);
|
|
|
|
check(numRespondents, Number);
|
|
|
|
|
2016-10-22 01:11:28 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2016-10-21 21:21:09 +08:00
|
|
|
requester: requesterId,
|
2016-10-22 01:11:28 +08:00
|
|
|
'poll.id': id,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
2016-10-21 21:21:09 +08:00
|
|
|
$set: {
|
2017-04-13 04:37:37 +08:00
|
|
|
requester: requesterId,
|
2016-10-22 01:42:43 +08:00
|
|
|
poll: {
|
|
|
|
answers: answers,
|
|
|
|
num_responders: numResponders,
|
|
|
|
num_respondents: numRespondents,
|
2017-04-13 04:33:14 +08:00
|
|
|
id,
|
2016-10-22 01:42:43 +08:00
|
|
|
},
|
2016-10-21 21:21:09 +08:00
|
|
|
},
|
2016-10-22 01:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
2016-10-22 01:42:43 +08:00
|
|
|
if (err) {
|
2016-10-22 02:56:42 +08:00
|
|
|
return Logger.error(`Updating Polls collection: ${err}`);
|
2016-10-22 01:11:28 +08:00
|
|
|
}
|
|
|
|
|
2016-10-22 02:56:42 +08:00
|
|
|
Logger.info(`Updating Polls collection (meetingId: ${meetingId}, pollId: ${id}!)`);
|
2016-10-22 01:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Polls.update(selector, modifier, cb);
|
2016-10-21 21:21:09 +08:00
|
|
|
};
|