2017-10-12 10:00:28 +08:00
|
|
|
import Polls from '/imports/api/polls';
|
2016-10-21 21:21:09 +08:00
|
|
|
import { check } from 'meteor/check';
|
2016-10-22 01:11:28 +08:00
|
|
|
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
|
|
|
|
2017-12-13 00:19:24 +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,
|
2017-12-13 00:19:24 +08:00
|
|
|
numResponders,
|
|
|
|
numRespondents,
|
2016-10-21 21:21:09 +08:00
|
|
|
} = poll;
|
|
|
|
|
|
|
|
check(id, String);
|
|
|
|
check(answers, Array);
|
|
|
|
|
|
|
|
check(numResponders, Number);
|
|
|
|
check(numRespondents, Number);
|
|
|
|
|
2016-10-22 01:11:28 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2017-10-12 08:33:57 +08:00
|
|
|
id,
|
2016-10-22 01:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
2017-12-13 00:19:24 +08:00
|
|
|
$set: flat(poll, { safe: true }),
|
2016-10-22 01:11:28 +08:00
|
|
|
};
|
|
|
|
|
2017-10-12 08:33:57 +08:00
|
|
|
const cb = (err) => {
|
2016-10-22 01:42:43 +08:00
|
|
|
if (err) {
|
2017-10-13 03:07:02 +08:00
|
|
|
return Logger.error(`Updating Polls collection: ${err}`);
|
2016-10-22 01:11:28 +08:00
|
|
|
}
|
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
return Logger.info(`Updating Polls collection (meetingId: ${meetingId}, pollId: ${id}!)`);
|
2016-10-22 01:11:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Polls.update(selector, modifier, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|