2017-07-03 23:05:35 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Users from '/imports/api/2.0/users/';
|
|
|
|
import addUser from '../modifiers/addUser';
|
|
|
|
import removeUser from '../modifiers/removeUser';
|
|
|
|
|
2017-07-07 02:01:05 +08:00
|
|
|
export default function handleGetUsers({ body }, meetingId) {
|
2017-07-03 23:05:35 +08:00
|
|
|
const { users } = body;
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
|
|
|
const usersIds = users.map(m => m.intId);
|
|
|
|
|
|
|
|
const usersToRemove = Users.find({
|
|
|
|
meetingId,
|
|
|
|
userId: { $nin: usersIds },
|
|
|
|
}).fetch();
|
|
|
|
|
|
|
|
usersToRemove.forEach(user => removeUser(meetingId, user.userId));
|
|
|
|
|
|
|
|
const usersAdded = [];
|
|
|
|
users.forEach((user) => {
|
|
|
|
usersAdded.push(addUser(meetingId, user));
|
|
|
|
});
|
|
|
|
|
|
|
|
return usersAdded;
|
|
|
|
}
|