bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/users/server/handlers/presenterAssigned.js
2017-07-17 09:00:18 -03:00

62 lines
1.3 KiB
JavaScript

import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import Users from '/imports/api/2.0/users';
const unassignCurrentPresenter = (meetingId, presenterId) => {
const selector = {
meetingId,
userId: { $ne: presenterId },
'user.presenter': true,
};
const modifier = {
$set: {
'user.presenter': false,
},
$pop: {
'user.roles': 'presenter',
},
};
const cb = (err) => {
if (err) {
return Logger.error(`Unassigning current presenter from collection: ${err}`);
}
return Logger.info(`Unassign current presenter meeting=${meetingId}`);
};
return Users.update(selector, modifier, cb);
};
export default function handlePresenterAssigned({ body }, meetingId) {
const { presenterId } = body;
check(presenterId, String);
const selector = {
meetingId,
userId: presenterId,
};
const modifier = {
$set: {
'user.presenter': true,
},
$push: {
'user.roles': 'presenter',
},
};
const cb = (err) => {
if (err) {
return Logger.error(`Assigning user as presenter: ${err}`);
}
unassignCurrentPresenter(meetingId, presenterId);
return Logger.info(`Assigned user as presenter id=${presenterId} meeting=${meetingId}`);
};
return Users.update(selector, modifier, cb);
}