2017-02-24 02:52:44 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
2017-06-19 19:57:32 +08:00
|
|
|
import Users from './../../';
|
2016-05-13 01:43:59 +08:00
|
|
|
|
2017-02-24 02:52:44 +08:00
|
|
|
export default function createDummyUser(meetingId, userId, authToken) {
|
|
|
|
check(meetingId, String);
|
|
|
|
check(userId, String);
|
|
|
|
check(authToken, String);
|
|
|
|
|
|
|
|
const User = Users.findOne({ meetingId, userId });
|
|
|
|
if (User) {
|
2017-06-03 03:25:02 +08:00
|
|
|
throw new Meteor.Error('existing-user', 'Tried to create a dummy user for an existing user');
|
2016-05-16 22:35:59 +08:00
|
|
|
}
|
2017-02-24 02:52:44 +08:00
|
|
|
|
|
|
|
const doc = {
|
|
|
|
meetingId,
|
|
|
|
userId,
|
|
|
|
authToken,
|
|
|
|
clientType: 'HTML5',
|
2017-03-11 03:18:23 +08:00
|
|
|
validated: null,
|
2017-02-24 02:52:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const cb = (err, numChanged) => {
|
|
|
|
if (err) {
|
|
|
|
return Logger.error(`Creating dummy user to collection: ${err}`);
|
|
|
|
}
|
|
|
|
|
2017-04-28 04:07:27 +08:00
|
|
|
Logger.info(`Created dummy user id=${userId} token=${authToken} meeting=${meetingId}`);
|
2017-02-24 02:52:44 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return Users.insert(doc, cb);
|
2017-06-03 03:25:02 +08:00
|
|
|
}
|