2016-05-13 03:50:02 +08:00
|
|
|
import Polls from '/imports/api/polls';
|
2016-10-22 01:11:28 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2016-10-21 21:21:09 +08:00
|
|
|
import { check } from 'meteor/check';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2016-10-21 21:21:09 +08:00
|
|
|
export default function addPoll(poll, requesterId, users, meetingId) {
|
|
|
|
check(poll, Object);
|
|
|
|
check(requesterId, String);
|
|
|
|
check(users, Array);
|
2016-10-22 01:11:28 +08:00
|
|
|
|
|
|
|
if (meetingId) {
|
|
|
|
check(meetingId, String);
|
|
|
|
}
|
2016-10-21 21:21:09 +08:00
|
|
|
|
|
|
|
const userIds = users.map(user => user.user.userid);
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2016-10-22 01:11:28 +08:00
|
|
|
const modifier = {
|
|
|
|
meetingId,
|
|
|
|
poll,
|
2016-05-16 22:35:59 +08:00
|
|
|
requester: requesterId,
|
2016-10-21 21:21:09 +08:00
|
|
|
users: userIds,
|
2016-05-16 22:35:59 +08:00
|
|
|
};
|
2016-10-22 01:11:28 +08:00
|
|
|
|
|
|
|
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);
|
2016-05-13 01:43:59 +08:00
|
|
|
};
|