2017-06-19 21:13:35 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-10-12 10:00:28 +08:00
|
|
|
import Users from '/imports/api/users';
|
2017-06-19 21:13:35 +08:00
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
export default async function createDummyUser(meetingId, userId, authToken) {
|
2017-06-19 21:13:35 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
check(authToken, String);
|
|
|
|
|
2023-03-15 21:18:31 +08:00
|
|
|
const User = await Users.findOneAsync({ meetingId, userId });
|
2017-06-29 02:34:22 +08:00
|
|
|
if (User) {
|
2017-06-19 21:13:35 +08:00
|
|
|
throw new Meteor.Error('existing-user', 'Tried to create a dummy user for an existing user');
|
|
|
|
}
|
|
|
|
|
|
|
|
const doc = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
authToken,
|
|
|
|
clientType: 'HTML5',
|
|
|
|
validated: null,
|
2022-01-07 22:37:23 +08:00
|
|
|
left: false,
|
2017-06-19 21:13:35 +08:00
|
|
|
};
|
|
|
|
|
2020-11-23 21:13:46 +08:00
|
|
|
try {
|
2023-03-15 21:18:31 +08:00
|
|
|
const insertedId = await Users.insertAsync(doc);
|
2020-11-23 21:13:46 +08:00
|
|
|
|
|
|
|
if (insertedId) {
|
2017-12-13 23:45:54 +08:00
|
|
|
Logger.info(`Created dummy user id=${userId} token=${authToken} meeting=${meetingId}`);
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|
2020-11-23 21:13:46 +08:00
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Creating dummy user to collection: ${err}`);
|
|
|
|
}
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|