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

42 lines
856 B
JavaScript
Raw Normal View History

import Polls from '/imports/api/polls';
2016-10-21 21:21:09 +08:00
import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
2017-10-12 08:33:57 +08:00
import flat from 'flat';
2016-10-21 21:21:09 +08:00
export default function updateVotes(poll, meetingId) {
2016-10-21 21:21:09 +08:00
check(meetingId, String);
check(poll, Object);
const {
id,
answers,
numResponders,
numRespondents,
2016-10-21 21:21:09 +08:00
} = poll;
check(id, String);
check(answers, Array);
check(numResponders, Number);
check(numRespondents, Number);
const selector = {
meetingId,
2017-10-12 08:33:57 +08:00
id,
};
const modifier = {
$set: flat(poll, { safe: true }),
};
try {
const numberAffected = Polls.update(selector, modifier);
if (numberAffected) {
Logger.info(`Updating Polls collection vote (meetingId: ${meetingId}, pollId: ${id}!)`);
}
} catch (err) {
Logger.error(`Updating Polls collection vote: ${err}`);
}
2017-06-03 03:25:02 +08:00
}