2016-11-12 03:02:46 +08:00
|
|
|
import { check } from 'meteor/check';
|
2017-10-12 08:40:51 +08:00
|
|
|
import Presentations from '/imports/api/2.0/presentations';
|
2016-11-12 03:02:46 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 08:40:51 +08:00
|
|
|
import flat from 'flat';
|
2016-11-12 03:02:46 +08:00
|
|
|
|
2017-10-12 08:40:51 +08:00
|
|
|
import addSlide from '/imports/api/2.0/slides/server/modifiers/addSlide';
|
|
|
|
import setCurrentPresentation from './setCurrentPresentation';
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
const addSlides = (meetingId, presentationId, slides) => {
|
2017-06-03 03:25:02 +08:00
|
|
|
const slidesAdded = [];
|
2016-11-12 03:02:46 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
slides.forEach((slide) => {
|
2016-11-12 03:02:46 +08:00
|
|
|
slidesAdded.push(addSlide(meetingId, presentationId, slide));
|
|
|
|
});
|
|
|
|
|
|
|
|
return slidesAdded;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function addPresentation(meetingId, presentation) {
|
2017-10-12 08:40:51 +08:00
|
|
|
check(presentation, {
|
|
|
|
id: String,
|
|
|
|
name: String,
|
|
|
|
current: Boolean,
|
|
|
|
pages: [
|
|
|
|
{
|
|
|
|
id: String,
|
|
|
|
num: Number,
|
|
|
|
thumbUri: String,
|
|
|
|
swfUri: String,
|
|
|
|
txtUri: String,
|
|
|
|
svgUri: String,
|
|
|
|
current: Boolean,
|
|
|
|
xOffset: Number,
|
|
|
|
yOffset: Number,
|
|
|
|
widthRatio: Number,
|
|
|
|
heightRatio: Number,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
downloadable: Boolean,
|
|
|
|
});
|
2016-11-12 03:02:46 +08:00
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
2017-10-12 08:40:51 +08:00
|
|
|
id: presentation.id,
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
2017-10-12 08:40:51 +08:00
|
|
|
$set: Object.assign({
|
2016-11-12 03:02:46 +08:00
|
|
|
meetingId,
|
2017-10-12 08:40:51 +08:00
|
|
|
'conversion.done': true,
|
|
|
|
'conversion.error': false,
|
|
|
|
}, flat(presentation, { safe: true })),
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
2017-10-12 08:40:51 +08:00
|
|
|
return Logger.error(`Adding presentation2x to collection: ${err}`);
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
addSlides(meetingId, presentation.id, presentation.pages);
|
|
|
|
|
|
|
|
const { insertedId } = numChanged;
|
|
|
|
if (insertedId) {
|
2017-10-12 08:40:51 +08:00
|
|
|
if (presentation.current) {
|
|
|
|
setCurrentPresentation(meetingId, presentation.id);
|
|
|
|
}
|
2016-11-12 03:02:46 +08:00
|
|
|
|
2017-10-12 08:40:51 +08:00
|
|
|
return Logger.info(`Added presentation2x id=${presentation.id} meeting=${meetingId}`);
|
2016-11-12 03:02:46 +08:00
|
|
|
}
|
2017-10-12 08:40:51 +08:00
|
|
|
|
|
|
|
return Logger.info(`Upserted presentation2x id=${presentation.id} meeting=${meetingId}`);
|
2016-11-12 03:02:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Presentations.upsert(selector, modifier, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|