bigbluebutton-Github/bigbluebutton-html5/imports/api/polls/server/methods/publishVote.js
Klaus Klein b574859ab2 Merge remote-tracking branch 'upstream/master' into Acl
* upstream/master:
  Improve lint script
  Update package-lock with the new packages
  Add missing packages and fix formating
  Switched from 2 deprecated packages
  Corrected findDOMNode import for the poll shape
  Switched from the deprecated react-addons-css-transition-group package to a recommended one
  Updated react-meteor-data to remove a new React 15 warning
  Updated main packages
  Switched to prop-types package to remove new React 15 warnings
  Improve ESLint rules
  Linter auto fix
  Change lint import configs to our pattern
  Remove autofix script
  Replace JSCS in favor of ESLint
2017-06-05 13:52:37 -03:00

57 lines
1.5 KiB
JavaScript

import RedisPubSub from '/imports/startup/server/redis';
import { check } from 'meteor/check';
import Polls from '/imports/api/polls';
import Logger from '/imports/startup/server/logger';
export default function publishVote(credentials, pollId, pollAnswerId) { // TODO discuss location
const REDIS_CONFIG = Meteor.settings.redis;
const CHANNEL = REDIS_CONFIG.channels.toBBBApps.polling;
const EVENT_NAME = 'vote_poll_user_request_message';
const { meetingId, requesterUserId, requesterToken } = credentials;
const currentPoll = Polls.findOne({
users: requesterUserId,
meetingId,
'poll.answers.id': pollAnswerId,
'poll.id': pollId,
});
check(meetingId, String);
check(requesterUserId, String);
check(pollAnswerId, Number);
check(currentPoll.meetingId, String);
const payload = {
meeting_id: currentPoll.meetingId,
user_id: requesterUserId,
poll_id: currentPoll.poll.id,
question_id: 0,
answer_id: pollAnswerId,
};
const selector = {
users: requesterUserId,
meetingId,
'poll.answers.id': pollAnswerId,
};
const modifier = {
$pull: {
users: requesterUserId,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Updating Polls collection: ${err}`);
}
Logger.info(`Updating Polls collection (meetingId: ${meetingId},
pollId: ${currentPoll.poll.id}!)`);
};
Polls.update(selector, modifier, cb);
return RedisPubSub.publish(CHANNEL, EVENT_NAME, payload);
}