bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/breakouts/server/modifiers/addBreakout.js

42 lines
900 B
JavaScript
Raw Normal View History

2017-06-27 02:00:28 +08:00
import { check } from 'meteor/check';
2017-06-27 20:45:08 +08:00
import Logger from '/imports/startup/server/logger';
2017-07-14 04:21:27 +08:00
import Breakouts from '/imports/api/2.0/breakouts';
2017-07-25 21:51:33 +08:00
import flat from 'flat';
2017-06-27 02:00:28 +08:00
2017-06-27 20:45:08 +08:00
export default function addBreakout(breakout) {
2017-06-27 02:00:28 +08:00
const {
breakoutMeetingId,
parentId,
name,
2017-06-27 20:45:08 +08:00
} = breakout;
2017-06-27 02:00:28 +08:00
check(breakoutMeetingId, String);
check(parentId, String);
check(name, String);
const selector = { breakoutMeetingId };
const modifier = {
2017-07-25 21:51:33 +08:00
$set:
flat(breakout, { safe: true })
,
2017-06-27 02:00:28 +08:00
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Adding breakout to collection: ${err}`);
}
const {
insertedId,
} = numChanged;
if (insertedId) {
return Logger.info(`Added breakout id=${breakoutMeetingId}`);
}
return Logger.info(`Upserted breakout id=${breakoutMeetingId}`);
};
return Breakouts.upsert(selector, modifier, cb);
}