bigbluebutton-Github/bigbluebutton-html5/imports/api/pads/server/modifiers/createGroup.js
2023-03-20 16:38:31 -03:00

40 lines
1.1 KiB
JavaScript

import { check } from 'meteor/check';
import Pads from '/imports/api/pads';
import Logger from '/imports/startup/server/logger';
import createPad from '/imports/api/pads/server/methods/createPad';
export default async function createGroup(meetingId, userId, externalId, model, name) {
try {
check(meetingId, String);
check(userId, String);
check(externalId, String);
check(model, String);
check(name, String);
const selector = {
meetingId,
externalId,
};
const modifier = {
meetingId,
externalId,
model,
name,
};
const { insertedId } = await Pads.upsertAsync(selector, modifier);
if (insertedId) {
Logger.info(`Added pad group external=${externalId} meeting=${meetingId}`);
// Each group will get only one pad so we can control access per pad. The pad's name
// will be the group's externalId
createPad(meetingId, userId, externalId, externalId);
} else {
Logger.info(`Upserted pad group external=${externalId} meeting=${meetingId}`);
}
} catch (err) {
Logger.error(`Adding pad group to the collection: ${err}`);
}
}