2022-03-24 21:56:07 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
|
|
|
|
export default function userBreakoutChanged({ body }) {
|
|
|
|
check(body, Object);
|
|
|
|
|
|
|
|
const {
|
2022-04-12 20:50:19 +08:00
|
|
|
meetingId,
|
2022-03-24 21:56:07 +08:00
|
|
|
userId,
|
|
|
|
fromBreakoutId,
|
|
|
|
toBreakoutId,
|
2022-04-12 20:50:19 +08:00
|
|
|
redirectToHtml5JoinURL,
|
2022-03-24 21:56:07 +08:00
|
|
|
} = body;
|
|
|
|
|
2022-04-12 20:50:19 +08:00
|
|
|
check(meetingId, String);
|
2022-03-24 21:56:07 +08:00
|
|
|
check(userId, String);
|
|
|
|
check(fromBreakoutId, String);
|
|
|
|
check(toBreakoutId, String);
|
2022-04-12 20:50:19 +08:00
|
|
|
check(redirectToHtml5JoinURL, String);
|
2022-03-24 21:56:07 +08:00
|
|
|
|
|
|
|
const oldBreakoutSelector = {
|
2022-04-12 20:50:19 +08:00
|
|
|
parentMeetingId: meetingId,
|
2022-03-24 21:56:07 +08:00
|
|
|
breakoutId: fromBreakoutId,
|
2022-04-14 01:22:02 +08:00
|
|
|
freeJoin: false,
|
2022-03-24 21:56:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const newBreakoutSelector = {
|
2022-04-12 20:50:19 +08:00
|
|
|
parentMeetingId: meetingId,
|
2022-03-24 21:56:07 +08:00
|
|
|
breakoutId: toBreakoutId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const oldModifier = {
|
|
|
|
$unset: {
|
|
|
|
[`url_${userId}`]: '',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const newModifier = {
|
|
|
|
$set: {
|
|
|
|
[`url_${userId}`]: {
|
2022-04-12 20:50:19 +08:00
|
|
|
redirectToHtml5JoinURL,
|
2022-03-24 21:56:07 +08:00
|
|
|
insertedTime: new Date().getTime(),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
2022-04-13 00:56:54 +08:00
|
|
|
let numberAffectedRows = 0;
|
2022-03-24 21:56:07 +08:00
|
|
|
|
2022-04-13 00:56:54 +08:00
|
|
|
if (oldBreakoutSelector.breakoutId !== '') {
|
|
|
|
numberAffectedRows += Breakouts.update(oldBreakoutSelector, oldModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newBreakoutSelector.breakoutId !== '') {
|
|
|
|
numberAffectedRows += Breakouts.update(newBreakoutSelector, newModifier);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numberAffectedRows > 0) {
|
2022-03-24 21:56:07 +08:00
|
|
|
Logger.info(`Updated user breakout for userId=${userId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating user breakout: ${err}`);
|
|
|
|
}
|
|
|
|
}
|