bigbluebutton-Github/bigbluebutton-html5/imports/api/users/server/modifiers/changeRole.js

35 lines
725 B
JavaScript
Raw Normal View History

import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/2.0/users';
2017-10-07 00:16:55 +08:00
export default function changeRole({ body }, meetingId) {
const { userId, role, changedBy } = body;
const selector = {
meetingId,
userId,
};
const modifier = {
$set: {
role,
2017-10-07 01:52:14 +08:00
},
$push: {
roles: (role === 'MODERATOR' ? 'moderator' : 'viewer'),
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Changed user role: ${err}`);
}
if (numChanged) {
return Logger.info(`Changed user role ${role} id=${userId} meeting=${meetingId} by changedBy=${changedBy}`);
}
2017-10-07 01:56:56 +08:00
return null;
};
return Users.update(selector, modifier, cb);
}