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
|
|
|
|
2017-10-13 03:07:02 +08:00
|
|
|
export default function createDummyUser(meetingId, userId, authToken) {
|
2017-06-19 21:13:35 +08:00
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
check(authToken, String);
|
|
|
|
|
2017-06-29 02:34:22 +08:00
|
|
|
const User = Users.findOne({ meetingId, userId });
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
2017-10-06 20:50:01 +08:00
|
|
|
Logger.error(`Creating dummy user to collection: ${err}`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (numChanged) {
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-29 02:14:29 +08:00
|
|
|
return Users.insert(doc, cb);
|
2017-06-19 21:13:35 +08:00
|
|
|
}
|