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,
|
|
|
|
};
|
|
|
|
|
|
|
|
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 {
|
|
|
|
const numberAffectedOld = Breakouts.update(oldBreakoutSelector, oldModifier);
|
|
|
|
const numberAffectedNew = Breakouts.update(newBreakoutSelector, newModifier);
|
|
|
|
|
|
|
|
if (numberAffectedOld && numberAffectedNew) {
|
|
|
|
Logger.info(`Updated user breakout for userId=${userId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating user breakout: ${err}`);
|
|
|
|
}
|
|
|
|
}
|