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
|
|
|
|
2023-03-07 21:47:43 +08:00
|
|
|
export default async 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
|
|
|
};
|
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
try {
|
2023-03-07 21:47:43 +08:00
|
|
|
const numberAffected = await Polls.updateAsync(selector, modifier);
|
2016-10-22 01:11:28 +08:00
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
if (numberAffected) {
|
2021-06-17 10:20:49 +08:00
|
|
|
Logger.info(`Updating Polls collection vote (meetingId: ${meetingId}, pollId: ${id}!)`);
|
2020-11-27 00:23:57 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
2021-06-17 10:20:49 +08:00
|
|
|
Logger.error(`Updating Polls collection vote: ${err}`);
|
2020-11-27 00:23:57 +08:00
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|