bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/modifiers/updateVotes.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-10-21 21:21:09 +08:00
import Polls from '/imports/api/polls';
import { check } from 'meteor/check';
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);
const selector = {
meetingId,
2016-10-21 21:21:09 +08:00
requester: requesterId,
'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
},
};
const cb = (err, numChanged) => {
2016-10-22 01:42:43 +08:00
if (err) {
return Logger.error(`Updating Polls collection: ${err}`);
}
Logger.info(`Updating Polls collection (meetingId: ${meetingId}, pollId: ${id}!)`);
};
return Polls.update(selector, modifier, cb);
2016-10-21 21:21:09 +08:00
};