Remove callbacks from update and clear Mongo operations for randomly selecting a user

This commit is contained in:
Maxim Khlobystov 2021-01-19 01:53:13 +00:00
parent 88c6e773e3
commit 5238dac647
2 changed files with 19 additions and 20 deletions

View File

@ -9,18 +9,18 @@ export default function clearRandomlySelectedUser() {
meetingId,
};
const cb = (err) => {
if (err) return Logger.error(`Clearing randomly selected user : ${err}`);
Logger.info(`Cleared randomly selected user from meeting=${meetingId} by id=${requesterUserId}`);
const modifier = {
$set: {
randomlySelectedUser: '',
},
};
return Meetings.update(
selector,
{
$set: {
randomlySelectedUser: '',
},
},
cb,
);
try {
const { insertedId } = Meetings.update(selector, modifier);
if (insertedId) {
Logger.info(`Cleared randomly selected user from meeting=${meetingId} by id=${requesterUserId}`);
}
} catch (err) {
Logger.error(`Clearing randomly selected user : ${err}`);
}
}

View File

@ -17,13 +17,12 @@ export default function updateRandomUser(meetingId, userId, requesterId) {
},
};
const cb = (err) => {
if (err != null) {
return Logger.error(`Setting randomly selected userId=${userId} by requesterId=${requesterId} in meetingId=${meetingId}`);
try {
const { insertedId } = Meetings.upsert(selector, modifier);
if (insertedId) {
Logger.info(`Set randomly selected userId=${userId} by requesterId=${requesterId} in meeitingId=${meetingId}`);
}
return Logger.info(`Set randomly selected userId=${userId} by requesterId=${requesterId} in meeitingId=${meetingId}`);
};
return Meetings.upsert(selector, modifier, cb);
} catch (err) {
Logger.error(`Setting randomly selected userId=${userId} by requesterId=${requesterId} in meetingId=${meetingId}`);
}
}