2020-09-01 20:07:56 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import AuthTokenValidation from '/imports/api/auth-token-validation';
|
|
|
|
|
2023-03-16 20:19:53 +08:00
|
|
|
export default async function upsertValidationState(
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
validationStatus,
|
|
|
|
connectionId,
|
|
|
|
reason = null,
|
|
|
|
) {
|
2020-09-01 20:07:56 +08:00
|
|
|
const selector = {
|
|
|
|
meetingId, userId, connectionId,
|
|
|
|
};
|
|
|
|
const modifier = {
|
|
|
|
$set: {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
connectionId,
|
|
|
|
validationStatus,
|
2020-09-16 20:52:44 +08:00
|
|
|
updatedAt: new Date().getTime(),
|
2021-03-22 20:37:17 +08:00
|
|
|
reason,
|
2020-09-01 20:07:56 +08:00
|
|
|
},
|
|
|
|
};
|
2020-09-16 20:52:44 +08:00
|
|
|
|
2021-03-22 20:37:17 +08:00
|
|
|
try {
|
2023-03-16 20:19:53 +08:00
|
|
|
await AuthTokenValidation
|
|
|
|
.removeAsync({ meetingId, userId, connectionId: { $ne: connectionId } });
|
|
|
|
const { numberAffected } = AuthTokenValidation.upsertAsync(selector, modifier);
|
2021-03-22 20:37:17 +08:00
|
|
|
|
|
|
|
if (numberAffected) {
|
2020-09-01 20:07:56 +08:00
|
|
|
Logger.info(`Upserted ${JSON.stringify(selector)} ${validationStatus} in AuthTokenValidation`);
|
|
|
|
}
|
2021-03-22 20:37:17 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Could not upsert to collection AuthTokenValidation: ${err}`);
|
|
|
|
}
|
2020-09-01 20:07:56 +08:00
|
|
|
}
|