2018-05-12 00:01:24 +08:00
|
|
|
import { check } from 'meteor/check';
|
2023-03-01 22:52:39 +08:00
|
|
|
import { defaultsDeep } from '/imports/utils/array-utils';
|
2018-05-12 00:01:24 +08:00
|
|
|
|
2023-03-08 21:32:24 +08:00
|
|
|
async function addAnnotation(meetingId, whiteboardId, userId, annotation, Annotations) {
|
2022-05-04 20:40:56 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(whiteboardId, String);
|
|
|
|
check(annotation, Object);
|
2018-05-12 00:01:24 +08:00
|
|
|
|
|
|
|
const {
|
2023-03-01 22:52:39 +08:00
|
|
|
id, wbId,
|
2018-05-12 00:01:24 +08:00
|
|
|
} = annotation;
|
|
|
|
|
2022-10-21 22:05:31 +08:00
|
|
|
let { annotationInfo } = annotation;
|
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
id,
|
|
|
|
};
|
|
|
|
|
2023-03-08 21:32:24 +08:00
|
|
|
const oldAnnotation = await Annotations.findOneAsync(selector);
|
2022-10-21 22:05:31 +08:00
|
|
|
if (oldAnnotation) {
|
2023-03-01 22:52:39 +08:00
|
|
|
annotationInfo = defaultsDeep(annotationInfo, oldAnnotation.annotationInfo);
|
2022-10-21 22:05:31 +08:00
|
|
|
}
|
|
|
|
|
2018-05-12 00:01:24 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
whiteboardId,
|
|
|
|
meetingId,
|
|
|
|
id,
|
|
|
|
annotationInfo,
|
|
|
|
wbId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return { selector, modifier };
|
|
|
|
}
|
2023-03-08 21:32:24 +08:00
|
|
|
|
|
|
|
export default addAnnotation;
|