2019-08-01 03:10:41 +08:00
|
|
|
import { SlidePositions } from '/imports/api/slides';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import flat from 'flat';
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async function addSlidePositions(
|
2019-08-01 03:10:41 +08:00
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
presentationId,
|
|
|
|
slideId,
|
|
|
|
slidePosition,
|
|
|
|
) {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(podId, String);
|
|
|
|
check(presentationId, String);
|
|
|
|
check(slideId, String);
|
|
|
|
|
|
|
|
check(slidePosition, {
|
|
|
|
width: Number,
|
|
|
|
height: Number,
|
2022-08-16 20:12:43 +08:00
|
|
|
x: Number,
|
|
|
|
y: Number,
|
|
|
|
viewBoxWidth: Number,
|
|
|
|
viewBoxHeight: Number,
|
2019-08-01 03:10:41 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
podId,
|
|
|
|
presentationId,
|
|
|
|
id: slideId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: Object.assign(
|
|
|
|
{ meetingId },
|
|
|
|
{ podId },
|
|
|
|
{ presentationId },
|
|
|
|
{ id: slideId },
|
|
|
|
flat(slidePosition),
|
|
|
|
{ safe: true },
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-04-01 04:40:41 +08:00
|
|
|
const { insertedId } = await SlidePositions.upsertAsync(selector, modifier);
|
2019-08-01 03:10:41 +08:00
|
|
|
|
|
|
|
if (insertedId) {
|
2020-11-23 21:13:46 +08:00
|
|
|
Logger.info(`Added slide position id=${slideId} pod=${podId} presentation=${presentationId}`);
|
|
|
|
} else {
|
|
|
|
Logger.info(`Upserted slide position id=${slideId} pod=${podId} presentation=${presentationId}`);
|
2019-08-01 03:10:41 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding slide position to collection: ${err}`);
|
|
|
|
}
|
2019-08-01 03:10:41 +08:00
|
|
|
}
|