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

35 lines
798 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 async 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-11 18:13:57 +08:00
responses: { userId, answerIds },
2018-10-10 23:49:58 +08:00
},
};
try {
const numberAffected = await Polls.updateAsync(selector, modifier);
2018-10-10 23:49:58 +08:00
if (numberAffected) {
2021-02-11 18:13:57 +08:00
Logger.info(`Updating Poll response (userId: ${userId}, response: ${JSON.stringify(answerIds)}, pollId: ${pollId})`);
}
} catch (err) {
Logger.error(`Updating Poll responses: ${err}`);
}
2018-10-10 23:49:58 +08:00
}