bigbluebutton-Github/bigbluebutton-html5/imports/api/2.0/meetings/server/modifiers/addMeeting.js

41 lines
952 B
JavaScript
Raw Normal View History

2017-06-29 19:54:19 +08:00
import flat from 'flat';
2017-06-19 21:13:35 +08:00
import { check } from 'meteor/check';
import Meetings from '/imports/api/2.0/meetings';
import Logger from '/imports/startup/server/logger';
import initializeCursor from '/imports/api/1.1/cursor/server/modifiers/initializeCursor';
export default function addMeeting(meeting) {
const meetingId = meeting.meetingProp.intId;
check(meeting, Object);
check(meetingId, String);
const selector = {
'meetingProp.intId': meetingId,
};
const modifier = {
2017-06-29 19:54:19 +08:00
$set: flat(meeting),
2017-06-19 21:13:35 +08:00
};
const cb = (err, numChanged) => {
if (err) {
2017-06-29 19:54:19 +08:00
Logger.error(`Adding meeting to collection: ${err}`);
return;
2017-06-19 21:13:35 +08:00
}
initializeCursor(meetingId);
const { insertedId } = numChanged;
if (insertedId) {
2017-06-29 19:54:19 +08:00
Logger.info(`Added meeting2x id=${meetingId}`);
2017-06-19 21:13:35 +08:00
}
if (numChanged) {
2017-06-29 19:54:19 +08:00
Logger.info(`Upserted meeting2x id=${meetingId}`);
2017-06-19 21:13:35 +08:00
}
};
return Meetings.upsert(selector, modifier, cb);
}