2019-05-01 03:24:04 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2021-11-22 22:25:21 +08:00
|
|
|
import updateUserBreakoutRoom from '/imports/api/users-persistent-data/server/modifiers/updateUserBreakoutRoom';
|
2019-05-01 03:24:04 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { check } from 'meteor/check';
|
2022-12-14 02:00:13 +08:00
|
|
|
import { lowercaseTrim } from '/imports/utils/string-utils';
|
2019-05-01 03:24:04 +08:00
|
|
|
|
|
|
|
export default function joinedUsersChanged({ body }) {
|
|
|
|
check(body, Object);
|
|
|
|
|
|
|
|
const {
|
|
|
|
parentId,
|
|
|
|
breakoutId,
|
|
|
|
users,
|
|
|
|
} = body;
|
|
|
|
|
|
|
|
check(parentId, String);
|
|
|
|
check(breakoutId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
parentMeetingId: parentId,
|
|
|
|
breakoutId,
|
|
|
|
};
|
|
|
|
|
2022-12-14 02:00:13 +08:00
|
|
|
const usersMapped = users.map(user => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
|
2019-05-01 03:24:04 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
joinedUsers: usersMapped,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-02-24 03:42:21 +08:00
|
|
|
Breakouts.updateAsync(selector, modifier).then((res) => {
|
|
|
|
if (res.numberAffected) {
|
2021-11-11 21:10:31 +08:00
|
|
|
updateUserBreakoutRoom(parentId, breakoutId, users);
|
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
Logger.info(`Updated joined users in breakout id=${breakoutId}`);
|
2019-05-01 03:24:04 +08:00
|
|
|
}
|
2023-02-24 03:42:21 +08:00
|
|
|
}).catch((err) => {
|
2020-11-27 00:23:57 +08:00
|
|
|
Logger.error(`updating joined users in breakout: ${err}`);
|
2023-02-24 03:42:21 +08:00
|
|
|
});
|
2019-05-01 03:24:04 +08:00
|
|
|
}
|