Changes poll api to the correct conventions
This commit is contained in:
parent
a7335633d4
commit
0a873c302c
@ -1,9 +1,9 @@
|
||||
import RedisPubSub from '/imports/startup/server/redis';
|
||||
import handleShowResult from './handlers/showResult';
|
||||
import handlePollStopped from './handlers/pollStopped';
|
||||
import handlePollStarted from './handlers/pollStarted';
|
||||
import handleUserVoted from './handlers/userVoted';
|
||||
|
||||
RedisPubSub.on('poll_show_result_message', handleShowResult);
|
||||
RedisPubSub.on('poll_show_result_message', handlePollStopped);
|
||||
RedisPubSub.on('poll_started_message', handlePollStarted);
|
||||
RedisPubSub.on('poll_stopped_message', handleShowResult);
|
||||
RedisPubSub.on('poll_stopped_message', handlePollStopped);
|
||||
RedisPubSub.on('user_voted_poll_message', handleUserVoted);
|
||||
|
@ -19,14 +19,18 @@ export default function pollStarted({ payload }) {
|
||||
});
|
||||
|
||||
if (documentExists) {
|
||||
const users = Users.find({
|
||||
const selector = {
|
||||
meetingId: meetingId,
|
||||
}, {
|
||||
};
|
||||
|
||||
const options = {
|
||||
fields: {
|
||||
'user.userid': 1,
|
||||
_id: 0,
|
||||
},
|
||||
}).fetch();
|
||||
};
|
||||
|
||||
const users = Users.find(selector, options).fetch();
|
||||
|
||||
addPoll(poll, requesterId, users, meetingId);
|
||||
}
|
||||
|
@ -1,15 +1,22 @@
|
||||
import { check } from 'meteor/check';
|
||||
import removePoll from '../modifiers/removePoll';
|
||||
import clearPolls from '../modifiers/clearPolls';
|
||||
|
||||
export default function pollStopped({ payload }) {
|
||||
check(payload, Object);
|
||||
|
||||
console.log(payload);
|
||||
const meetingId = payload.meeting_id;
|
||||
const pollId = payload.poll.id;
|
||||
const poll = payload.poll;
|
||||
|
||||
check(meetingId, String);
|
||||
check(pollId, String);
|
||||
|
||||
clearPolls(meetingId, pollId);
|
||||
if (poll) {
|
||||
const pollId = poll.id;
|
||||
|
||||
check(pollId, String);
|
||||
|
||||
removePoll(meetingId, pollId);
|
||||
} else {
|
||||
clearPolls(meetingId);
|
||||
}
|
||||
}
|
@ -30,15 +30,20 @@ export default function publishVote(credentials, pollId, pollAnswerId) { //TODO
|
||||
answer_id: pollAnswerId,
|
||||
},
|
||||
};
|
||||
Polls.update({
|
||||
|
||||
const selector = {
|
||||
users: requesterUserId,
|
||||
meetingId: meetingId,
|
||||
'poll.answers.id': pollAnswerId,
|
||||
}, {
|
||||
};
|
||||
|
||||
const modifier = {
|
||||
$pull: {
|
||||
users: requesterUserId,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Polls.update(selector, modifier);
|
||||
message = appendMessageHeader(eventName, message);
|
||||
logger.info('publishing Poll response to redis');
|
||||
return publish(REDIS_CONFIG.channels.toBBBApps.polling, message);
|
||||
|
@ -1,37 +1,37 @@
|
||||
import Polls from '/imports/api/polls';
|
||||
import { logger } from '/imports/startup/server/logger';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
import { check } from 'meteor/check';
|
||||
|
||||
export default function addPoll(poll, requesterId, users, meetingId) {
|
||||
check(poll, Object);
|
||||
check(requesterId, String);
|
||||
check(users, Array);
|
||||
check(meetingId, String);
|
||||
|
||||
if (meetingId) {
|
||||
check(meetingId, String);
|
||||
}
|
||||
|
||||
const userIds = users.map(user => user.user.userid);
|
||||
|
||||
// adding the initial number of votes for each answer
|
||||
// _answers = poll.answers;
|
||||
// _answers_length = _answers.length;
|
||||
// for (j = 0; j < _answers_length; j++) {
|
||||
// answer = _answers[j];
|
||||
// answer.num_votes = 0;
|
||||
// }
|
||||
|
||||
// adding the initial number of responders and respondents to the poll, which will be displayed
|
||||
// for presenter (in HTML5 client) when they start the poll
|
||||
numResponders = -1;
|
||||
numRespondents = -1;
|
||||
|
||||
// adding all together and inserting into the Polls collection
|
||||
const newPoll = {
|
||||
meetingId: meetingId,
|
||||
poll: poll,
|
||||
const modifier = {
|
||||
meetingId,
|
||||
poll,
|
||||
requester: requesterId,
|
||||
users: userIds,
|
||||
num_responders: -1,
|
||||
num_respondents: -1,
|
||||
};
|
||||
logger.info(`added poll _id=[${poll.id}]:meetingId=[${meetingId}].`);
|
||||
return Polls.insert(newPoll);
|
||||
|
||||
const cb = (err, numChanged) => {
|
||||
if (err != null) {
|
||||
return Logger.error(`Adding poll to collection: ${err}`);
|
||||
}
|
||||
|
||||
const { insertedId } = numChanged;
|
||||
if (insertedId) {
|
||||
return Logger.info(`Added poll id=${poll.id}`);
|
||||
}
|
||||
|
||||
return Logger.info(`Added poll id=${poll.id}`);
|
||||
};
|
||||
|
||||
return Polls.insert(modifier, cb);
|
||||
};
|
||||
|
@ -1,18 +1,10 @@
|
||||
import Polls from '/imports/api/polls';
|
||||
import { check } from 'meteor/check';
|
||||
import { logger } from '/imports/startup/server/logger';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function clearPolls(meetingId, pollId) {
|
||||
//TODO make it so you can delete the polls based only on meetingId
|
||||
check(meetingId, String);
|
||||
check(pollId, String);
|
||||
|
||||
if (meetingId && pollId) {
|
||||
return Polls.remove({
|
||||
meetingId: meetingId,
|
||||
'poll.id': pollId,
|
||||
}, logger.info(`cleared Polls Collection (meetingId: ${meetingId}, pollId: ${pollId}!)`));
|
||||
export default function clearPolls(meetingId) {
|
||||
if (meetingId) {
|
||||
return Polls.remove({ meetingId, }, Logger.info(`Cleared Polls (${meetingId})`));
|
||||
} else {
|
||||
return Polls.remove({}, logger.info('cleared Polls Collection (all meetings)!'));
|
||||
return Polls.remove({}, Logger.info('Cleared Polls (all)'));
|
||||
}
|
||||
};
|
||||
|
@ -0,0 +1,17 @@
|
||||
import Polls from '/imports/api/polls';
|
||||
import { check } from 'meteor/check';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function removePoll(meetingId, pollId) {
|
||||
check(meetingId, String);
|
||||
check(pollId, String);
|
||||
|
||||
const selector = {
|
||||
meetingId,
|
||||
'poll.id': pollId,
|
||||
};
|
||||
|
||||
const cb = () => { Logger.info(`Removed Poll: (meetingId: ${meetingId}) (pollId: ${pollId})`); };
|
||||
|
||||
return Polls.remove(selector, cb);
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
import Polls from '/imports/api/polls';
|
||||
import { check } from 'meteor/check';
|
||||
import { logger } from '/imports/startup/server/logger';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function updatePoll(poll, meetingId, requesterId) {
|
||||
check(meetingId, String);
|
||||
@ -21,15 +21,27 @@ export default function updatePoll(poll, meetingId, requesterId) {
|
||||
check(numResponders, Number);
|
||||
check(numRespondents, Number);
|
||||
|
||||
return Polls.update({
|
||||
meetingId: meetingId,
|
||||
const selector = {
|
||||
meetingId,
|
||||
requester: requesterId,
|
||||
poll: { id: id },
|
||||
}, {
|
||||
'poll.id': id,
|
||||
};
|
||||
|
||||
const modifier = {
|
||||
$set: {
|
||||
poll: { answers: answers },
|
||||
poll: { num_responders: numResponders },
|
||||
poll: { num_respondents: numRespondents },
|
||||
},
|
||||
}, logger.info(`updating Polls Collection (meetingId: ${meetingId}, pollId: ${id}!)`));
|
||||
};
|
||||
|
||||
const cb = (err, numChanged) => {
|
||||
if (err != null) {
|
||||
return Logger.error(`updating Polls collection: ${err}`);
|
||||
}
|
||||
|
||||
Logger.info(`updating Polls collection (meetingId: ${meetingId}, pollId: ${id}!)`);
|
||||
};
|
||||
|
||||
return Polls.update(selector, modifier, cb);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user