bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/handlers/userResponded.js

35 lines
779 B
JavaScript
Raw Normal View History

2018-10-10 23:49:58 +08:00
import { check } from 'meteor/check';
import Polls from '/imports/api/polls';
import Logger from '/imports/startup/server/logger';
export default function userResponded({ body }) {
2021-02-04 22:43:04 +08:00
const { pollId, userId, answerIds } = body;
2018-10-10 23:49:58 +08:00
check(pollId, String);
check(userId, String);
2021-02-04 22:43:04 +08:00
check(answerIds, Array);
2018-10-10 23:49:58 +08:00
const selector = {
id: pollId,
};
const modifier = {
$pull: {
users: userId,
},
$push: {
2021-02-05 00:54:50 +08:00
responses: { userId, answerIds: answerIds },
2018-10-10 23:49:58 +08:00
},
};
try {
const numberAffected = Polls.update(selector, modifier);
2018-10-10 23:49:58 +08:00
if (numberAffected) {
2021-02-04 22:43:04 +08:00
Logger.info(`Updating Poll response (userId: ${userId}, response: ${answerIds[0]}, pollId: ${pollId})`);
}
} catch (err) {
Logger.error(`Updating Poll responses: ${err}`);
}
2018-10-10 23:49:58 +08:00
}