2017-10-12 10:00:28 +08:00
|
|
|
import Annotations from '/imports/api/annotations';
|
2016-11-19 01:35:28 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2023-03-08 21:32:24 +08:00
|
|
|
export default async function clearAnnotations(meetingId, whiteboardId, userId) {
|
2017-10-12 08:52:57 +08:00
|
|
|
const selector = {};
|
|
|
|
|
2016-11-19 01:35:28 +08:00
|
|
|
if (meetingId) {
|
2017-10-12 08:52:57 +08:00
|
|
|
selector.meetingId = meetingId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (whiteboardId) {
|
|
|
|
selector.whiteboardId = whiteboardId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
selector.userId = userId;
|
2016-11-19 01:35:28 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
try {
|
2023-03-08 21:32:24 +08:00
|
|
|
const numberAffected = await Annotations.removeAsync(selector);
|
2017-10-12 08:52:57 +08:00
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
if (userId) {
|
2020-12-01 04:59:12 +08:00
|
|
|
Logger.info(`Cleared Annotations for userId=${userId} where whiteboard=${whiteboardId}`);
|
2020-12-01 04:01:41 +08:00
|
|
|
return;
|
2020-11-25 04:44:13 +08:00
|
|
|
}
|
2017-10-12 08:52:57 +08:00
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
if (whiteboardId) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info(`Cleared Annotations for whiteboard=${whiteboardId}`);
|
2020-12-01 04:11:57 +08:00
|
|
|
return;
|
2020-11-25 04:44:13 +08:00
|
|
|
}
|
2017-11-28 03:23:38 +08:00
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
if (meetingId) {
|
2020-12-01 04:01:41 +08:00
|
|
|
Logger.info(`Cleared Annotations (${meetingId})`);
|
2020-12-01 04:11:57 +08:00
|
|
|
return;
|
2020-11-25 04:44:13 +08:00
|
|
|
}
|
2017-10-12 08:52:57 +08:00
|
|
|
|
2020-11-25 04:44:13 +08:00
|
|
|
Logger.info('Cleared Annotations (all)');
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Removing Annotations from collection: ${err}`);
|
|
|
|
}
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|