2017-02-24 01:46:03 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users/';
|
2017-02-24 01:46:03 +08:00
|
|
|
import addUser from '../modifiers/addUser';
|
|
|
|
import removeUser from '../modifiers/removeUser';
|
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
export default function handleGetUsers({ body }, meetingId) {
|
|
|
|
const { users } = body;
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
2017-10-12 09:02:23 +08:00
|
|
|
const usersIds = users.map(m => m.intId);
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
const usersToRemove = Users.find({
|
|
|
|
meetingId,
|
|
|
|
userId: { $nin: usersIds },
|
2019-08-22 20:05:06 +08:00
|
|
|
}, { fields: { userId: 1 } }).fetch();
|
2017-02-24 01:46:03 +08:00
|
|
|
|
|
|
|
usersToRemove.forEach(user => removeUser(meetingId, user.userId));
|
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const usersAdded = [];
|
|
|
|
users.forEach((user) => {
|
2017-02-24 01:46:03 +08:00
|
|
|
usersAdded.push(addUser(meetingId, user));
|
|
|
|
});
|
|
|
|
|
|
|
|
return usersAdded;
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|