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

48 lines
999 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
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;
2017-10-12 08:33:57 +08:00
const { numResponders } = poll;
const { numRespondents } = poll;
2016-10-21 21:21:09 +08:00
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,
2017-10-12 08:33:57 +08:00
id,
};
const modifier = {
2017-10-12 08:33:57 +08:00
$set: Object.assign(
{ requester: requesterId },
flat(poll, { safe: true }),
),
};
2017-10-12 08:33:57 +08:00
const cb = (err) => {
2016-10-22 01:42:43 +08:00
if (err) {
return Logger.error(`Updating Polls collection: ${err}`);
}
return Logger.info(`Updating Polls collection (meetingId: ${meetingId}, pollId: ${id}!)`);
};
return Polls.update(selector, modifier, cb);
2017-06-03 03:25:02 +08:00
}