2019-02-27 01:08:15 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import GuestUsers from '/imports/api/guest-users';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2022-01-12 11:08:43 +08:00
|
|
|
import updatePositionInWaitingQueue from '../methods/updatePositionInWaitingQueue';
|
2019-02-27 01:08:15 +08:00
|
|
|
|
|
|
|
const GUEST_STATUS_ALLOW = 'ALLOW';
|
|
|
|
const GUEST_STATUS_DENY = 'DENY';
|
2023-03-09 01:35:40 +08:00
|
|
|
export default async function setGuestStatus(meetingId, intId, status, approvedBy = null) {
|
2019-02-27 01:08:15 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(intId, String);
|
|
|
|
check(status, String);
|
|
|
|
|
|
|
|
const selector = {
|
|
|
|
meetingId,
|
|
|
|
intId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
approved: status === GUEST_STATUS_ALLOW,
|
|
|
|
denied: status === GUEST_STATUS_DENY,
|
|
|
|
approvedBy,
|
|
|
|
},
|
2023-03-09 01:35:40 +08:00
|
|
|
};
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
try {
|
2023-03-09 01:35:40 +08:00
|
|
|
const numberAffected = await GuestUsers.updateAsync(selector, modifier);
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
Logger.info(`Updated status=${status} user=${intId} meeting=${meetingId}`);
|
2022-01-21 02:24:25 +08:00
|
|
|
/** Update position of waiting users after user has been
|
2023-03-09 01:35:40 +08:00
|
|
|
* approved or denied by the moderator
|
2022-01-21 02:24:25 +08:00
|
|
|
*/
|
2023-03-09 01:35:40 +08:00
|
|
|
await updatePositionInWaitingQueue(meetingId);
|
2020-11-27 00:23:57 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Updating status=${status} user=${intId}: ${err}`);
|
|
|
|
}
|
2019-02-27 01:08:15 +08:00
|
|
|
}
|