2017-10-12 05:25:18 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Breakouts from '/imports/api/breakouts';
|
2017-10-12 05:25:18 +08:00
|
|
|
|
|
|
|
export default function handleBreakoutJoinURL({ body }) {
|
2016-11-14 19:57:10 +08:00
|
|
|
const {
|
2018-06-07 05:38:28 +08:00
|
|
|
redirectToHtml5JoinURL,
|
2017-10-12 05:25:18 +08:00
|
|
|
userId,
|
|
|
|
breakoutId,
|
|
|
|
} = body;
|
2016-11-14 19:57:10 +08:00
|
|
|
|
2018-06-07 05:38:28 +08:00
|
|
|
check(redirectToHtml5JoinURL, String);
|
2016-11-15 00:12:54 +08:00
|
|
|
|
2016-11-14 19:57:10 +08:00
|
|
|
const selector = {
|
2017-10-12 05:25:18 +08:00
|
|
|
breakoutId,
|
2016-11-14 19:57:10 +08:00
|
|
|
};
|
|
|
|
|
2021-10-01 21:44:01 +08:00
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
[`url_${userId}`]: {
|
2021-09-30 01:52:30 +08:00
|
|
|
redirectToHtml5JoinURL,
|
|
|
|
insertedTime: new Date().getTime(),
|
|
|
|
},
|
2018-06-07 05:24:09 +08:00
|
|
|
},
|
|
|
|
};
|
2017-10-12 05:25:18 +08:00
|
|
|
|
2020-11-25 21:54:18 +08:00
|
|
|
try {
|
2021-09-07 02:54:12 +08:00
|
|
|
const ATTEMPT_EVERY_MS = 1000;
|
2016-11-29 03:48:02 +08:00
|
|
|
|
2021-09-07 02:54:12 +08:00
|
|
|
let numberAffected = 0;
|
2023-02-24 03:42:21 +08:00
|
|
|
const updateBreakout = async () => {
|
|
|
|
numberAffected = await Breakouts.updateAsync(selector, modifier);
|
|
|
|
};
|
2021-09-07 02:54:12 +08:00
|
|
|
|
|
|
|
const updateBreakoutPromise = new Promise((resolve) => {
|
2023-02-24 03:42:21 +08:00
|
|
|
const updateBreakoutInterval = setInterval(async () => {
|
|
|
|
await updateBreakout();
|
2021-09-07 02:54:12 +08:00
|
|
|
if (numberAffected) {
|
|
|
|
resolve(clearInterval(updateBreakoutInterval));
|
|
|
|
}
|
|
|
|
}, ATTEMPT_EVERY_MS);
|
|
|
|
});
|
|
|
|
|
|
|
|
updateBreakoutPromise.then(() => {
|
2020-11-25 21:54:18 +08:00
|
|
|
Logger.info(`Upserted breakout id=${breakoutId}`);
|
2021-09-07 02:54:12 +08:00
|
|
|
});
|
2020-11-25 21:54:18 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Adding breakout to collection: ${err}`);
|
|
|
|
}
|
2016-11-14 19:57:10 +08:00
|
|
|
}
|