bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/polls/server/modifiers/addPoll.js

54 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-06-29 04:37:45 +08:00
import Users from '/imports/api/2.0/users';
import Polls from '/imports/api/2.0/polls';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
export default function addPoll(meetingId, requesterId, poll) {
check(poll, Object);
check(requesterId, String);
check(meetingId, String);
let selector = {
meetingId,
};
const options = {
fields: {
'user.userid': 1,
_id: 0,
},
};
const userIds = Users.find(selector, options)
.fetch()
.map(user => user.user.userid);
selector = {
meetingId,
requester: requesterId,
'poll.id': poll.id,
};
const modifier = {
meetingId,
poll,
requester: requesterId,
users: userIds,
};
const cb = (err, numChanged) => {
if (err != null) {
return Logger.error(`Adding Poll to collection: ${poll.id}`);
}
const { insertedId } = numChanged;
if (insertedId) {
return Logger.info(`Added Poll id=${poll.id}`);
}
return Logger.info(`Upserted Poll id=${poll.id}`);
};
return Polls.upsert(selector, modifier, cb);
}