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
|
|
|
|
2023-03-02 00:38:40 +08:00
|
|
|
export default async function joinedUsersChanged({ body }) {
|
2019-05-01 03:24:04 +08:00
|
|
|
check(body, Object);
|
|
|
|
|
|
|
|
const {
|
|
|
|
parentId,
|
|
|
|
breakoutId,
|
|
|
|
users,
|
|
|
|
} = body;
|
|
|
|
|
|
|
|
check(parentId, String);
|
|
|
|
check(breakoutId, String);
|
|
|
|
check(users, Array);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
parentMeetingId: parentId,
|
|
|
|
breakoutId,
|
|
|
|
};
|
|
|
|
|
2023-03-02 00:38:40 +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-03-20 21:21:34 +08:00
|
|
|
try {
|
|
|
|
const numberAffected = await Breakouts.updateAsync(selector, modifier);
|
2021-11-11 21:10:31 +08:00
|
|
|
|
2023-03-20 21:21:34 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
await updateUserBreakoutRoom(parentId, breakoutId, users);
|
|
|
|
|
|
|
|
Logger.info(`Updated joined users in breakout id=${breakoutId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`updating joined users in breakout: ${err}`);
|
2023-03-02 00:38:40 +08:00
|
|
|
}
|
|
|
|
// .then((res) => {
|
|
|
|
// if (res.numberAffected) {
|
|
|
|
// updateUserBreakoutRoom(parentId, breakoutId, users);
|
|
|
|
|
|
|
|
// Logger.info(`Updated joined users in breakout id=${breakoutId}`);
|
|
|
|
// }
|
|
|
|
// }).catch((err) => {
|
|
|
|
// Logger.error(`updating joined users in breakout: ${err}`);
|
|
|
|
// });
|
2019-05-01 03:24:04 +08:00
|
|
|
}
|