Make all handlers async

This commit is contained in:
Tainan Felipe 2023-03-01 13:38:40 -03:00
parent 593333200d
commit 2553c44643
5 changed files with 43 additions and 39 deletions

View File

@ -1,9 +1,9 @@
import { check } from 'meteor/check';
import clearBreakouts from '../modifiers/clearBreakouts';
export default function handleBreakoutClosed({ body }) {
export default async function handleBreakoutClosed({ body }) {
const { breakoutId } = body;
check(breakoutId, String);
return clearBreakouts(breakoutId);
const result = await clearBreakouts(breakoutId);
return result;
}

View File

@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Breakouts from '/imports/api/breakouts';
export default function handleBreakoutJoinURL({ body }) {
export default async function handleBreakoutJoinURL({ body }) {
const {
redirectToHtml5JoinURL,
userId,
@ -32,7 +32,7 @@ export default function handleBreakoutJoinURL({ body }) {
numberAffected = await Breakouts.updateAsync(selector, modifier);
};
const updateBreakoutPromise = new Promise((resolve) => {
await new Promise((resolve) => {
const updateBreakoutInterval = setInterval(async () => {
await updateBreakout();
if (numberAffected) {
@ -40,10 +40,7 @@ export default function handleBreakoutJoinURL({ body }) {
}
}, ATTEMPT_EVERY_MS);
});
updateBreakoutPromise.then(() => {
Logger.info(`Upserted breakout id=${breakoutId}`);
});
} catch (err) {
Logger.error(`Adding breakout to collection: ${err}`);
}

View File

@ -4,7 +4,7 @@ import { check } from 'meteor/check';
import flat from 'flat';
import handleBreakoutRoomsListHist from '/imports/api/breakouts-history/server/handlers/breakoutRoomsList';
export default function handleBreakoutRoomsList({ body }, meetingId) {
export default async function handleBreakoutRoomsList({ body }, meetingId) {
// 0 seconds default breakout time, forces use of real expiration time
const DEFAULT_TIME_REMAINING = 0;
@ -14,7 +14,7 @@ export default function handleBreakoutRoomsList({ body }, meetingId) {
} = body;
// set firstly the last seq, then client will know when receive all
rooms.sort((a, b) => ((a.sequence < b.sequence) ? 1 : -1)).forEach((breakout) => {
await rooms.sort((a, b) => ((a.sequence < b.sequence) ? 1 : -1)).forEach(async (breakout) => {
const { breakoutId, html5JoinUrls, ...breakoutWithoutUrls } = breakout;
check(meetingId, String);
@ -43,15 +43,13 @@ export default function handleBreakoutRoomsList({ body }, meetingId) {
...urls,
},
};
Breakouts.upsertAsync(selector, modifier).then((res) => {
if (res.numberAffected) {
const numberAffected = await Breakouts.upsertAsync(selector, modifier);
if (numberAffected) {
Logger.info('Updated timeRemaining and externalMeetingId '
+ `for breakout id=${breakoutId}`);
} else {
Logger.error(`updating breakout: ${numberAffected}`);
}
}).catch((err) => {
Logger.error(`updating breakout: ${err}`);
}).finally(() => {
handleBreakoutRoomsListHist({ body });
});
});
}

View File

@ -4,7 +4,7 @@ import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import { lowercaseTrim } from '/imports/utils/string-utils';
export default function joinedUsersChanged({ body }) {
export default async function joinedUsersChanged({ body }) {
check(body, Object);
const {
@ -22,20 +22,29 @@ export default function joinedUsersChanged({ body }) {
breakoutId,
};
const usersMapped = users.map(user => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
const usersMapped = users
.map((user) => ({ userId: user.id, name: user.name, sortName: lowercaseTrim(user.name) }));
const modifier = {
$set: {
joinedUsers: usersMapped,
},
};
Breakouts.updateAsync(selector, modifier).then((res) => {
if (res.numberAffected) {
const numberAffected = await Breakouts.updateAsync(selector, modifier);
if (numberAffected) {
updateUserBreakoutRoom(parentId, breakoutId, users);
Logger.info(`Updated joined users in breakout id=${breakoutId}`);
} else {
Logger.error(`updating joined users in breakout: ${numberAffected}`);
}
}).catch((err) => {
Logger.error(`updating joined users in breakout: ${err}`);
});
// .then((res) => {
// if (res.numberAffected) {
// updateUserBreakoutRoom(parentId, breakoutId, users);
// Logger.info(`Updated joined users in breakout id=${breakoutId}`);
// }
// }).catch((err) => {
// Logger.error(`updating joined users in breakout: ${err}`);
// });
}

View File

@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Breakouts from '/imports/api/breakouts';
export default function handleUpdateTimeRemaining({ body }, meetingId) {
export default async function handleUpdateTimeRemaining({ body }, meetingId) {
const {
timeRemaining,
} = body;
@ -23,11 +23,11 @@ export default function handleUpdateTimeRemaining({ body }, meetingId) {
const options = {
multi: true,
};
Breakouts.updateAsync(selector, modifier, options).then((res) => {
if (res.numberAffected) {
const numberAffected = Breakouts.updateAsync(selector, modifier, options);
if (numberAffected) {
Logger.info(`Updated breakout time remaining for breakouts where parentMeetingId=${meetingId}`);
} else {
Logger.error(`Updating breakouts: ${numberAffected}`);
}
}).catch((err) => {
Logger.error(`Updating breakouts: ${err}`);
});
}