2018-04-06 03:59:26 +08:00
|
|
|
import { Match, check } from 'meteor/check';
|
|
|
|
import PresentationPods from '/imports/api/presentation-pods';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2018-04-06 06:29:58 +08:00
|
|
|
import addPresentation from '/imports/api/presentations/server/modifiers/addPresentation';
|
2018-04-06 03:59:26 +08:00
|
|
|
|
2018-04-06 06:29:58 +08:00
|
|
|
export default function addPresentationPod(meetingId, pod, presentations = undefined /* ?? */) {
|
2018-04-06 03:59:26 +08:00
|
|
|
check(meetingId, String);
|
2018-04-06 06:29:58 +08:00
|
|
|
check(presentations, Match.Maybe(Array));
|
2018-04-06 03:59:26 +08:00
|
|
|
check(pod, {
|
|
|
|
currentPresenterId: String,
|
|
|
|
podId: String,
|
|
|
|
});
|
|
|
|
|
|
|
|
const { currentPresenterId, podId } = pod;
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
currentPresenterId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Adding presentation pod to the collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:29:58 +08:00
|
|
|
// presentations object is currently passed together with Sync message
|
|
|
|
if (presentations) {
|
|
|
|
presentations.forEach(presentation => addPresentation(meetingId, podId, presentation));
|
|
|
|
}
|
|
|
|
|
2018-04-06 03:59:26 +08:00
|
|
|
if (numChanged) {
|
|
|
|
return Logger.info(`Added presentation pod id=${podId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Logger.info(`Upserted presentation pod id=${podId} meeting=${meetingId}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
return PresentationPods.upsert(selector, modifier, cb);
|
|
|
|
}
|