2022-10-24 21:11:28 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import { default as Pads } from '/imports/api/pads';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
|
2023-03-16 22:00:45 +08:00
|
|
|
export default async function pinPad(meetingId, externalId, pinned) {
|
2022-10-24 21:11:28 +08:00
|
|
|
try {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(externalId, String);
|
|
|
|
check(pinned, Boolean);
|
|
|
|
|
|
|
|
if (pinned) {
|
2023-03-16 22:00:45 +08:00
|
|
|
await Pads.updateAsync({ meetingId, pinned: true }, { $set: { pinned: false } });
|
2022-10-24 21:11:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
externalId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
pinned,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-03-16 22:00:45 +08:00
|
|
|
const numberAffected = await Pads.updateAsync(selector, modifier);
|
2022-10-24 21:11:28 +08:00
|
|
|
|
|
|
|
if (numberAffected) {
|
|
|
|
const prefix = pinned ? '' : 'un';
|
|
|
|
Logger.debug(`Pad ${prefix}pinned external=${externalId} meeting=${meetingId}`);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Pinning pad: ${err}`);
|
|
|
|
}
|
|
|
|
}
|