2019-02-27 01:08:15 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import GuestUsers from '/imports/api/guest-users/';
|
2022-01-12 11:08:43 +08:00
|
|
|
import updatePositionInWaitingQueue from '../methods/updatePositionInWaitingQueue';
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
export default async function handleGuestsWaitingForApproval({ body }, meetingId) {
|
2019-02-27 01:08:15 +08:00
|
|
|
const { guests } = body;
|
|
|
|
check(guests, Array);
|
2019-04-05 21:18:24 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
const result = await Promise.all(guests.map(async (guest) => {
|
2020-11-27 00:23:57 +08:00
|
|
|
try {
|
2023-04-01 04:40:41 +08:00
|
|
|
const { insertedId, numberAffected } = await GuestUsers.upsertAsync({
|
2020-11-27 00:23:57 +08:00
|
|
|
meetingId,
|
|
|
|
intId: guest.intId,
|
|
|
|
}, {
|
|
|
|
approved: false,
|
|
|
|
denied: false,
|
|
|
|
...guest,
|
|
|
|
meetingId,
|
2021-02-17 20:39:36 +08:00
|
|
|
loginTime: guest.registeredOn,
|
2022-01-12 22:10:30 +08:00
|
|
|
privateGuestLobbyMessage: '',
|
2020-11-27 00:23:57 +08:00
|
|
|
});
|
2019-02-27 01:08:15 +08:00
|
|
|
|
2020-11-27 00:23:57 +08:00
|
|
|
if (insertedId) {
|
|
|
|
Logger.info(`Added guest user meeting=${meetingId}`);
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
/** Update position of waiting users after user
|
2022-01-12 11:08:43 +08:00
|
|
|
* has entered the guest lobby
|
|
|
|
*/
|
2023-04-01 04:40:41 +08:00
|
|
|
updatePositionInWaitingQueue(meetingId);
|
2020-11-27 00:23:57 +08:00
|
|
|
} else if (numberAffected) {
|
|
|
|
Logger.info(`Upserted guest user meeting=${meetingId}`);
|
2022-01-12 11:08:43 +08:00
|
|
|
|
2023-04-01 04:40:41 +08:00
|
|
|
updatePositionInWaitingQueue(meetingId);
|
2020-11-27 00:23:57 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding guest user to collection: ${err}`);
|
2019-02-27 01:08:15 +08:00
|
|
|
}
|
2023-04-01 04:40:41 +08:00
|
|
|
}));
|
|
|
|
return result;
|
2019-02-27 01:08:15 +08:00
|
|
|
}
|