2017-05-11 18:36:32 +02:00
|
|
|
const config = require('../../config/config');
|
2017-05-10 11:04:06 +02:00
|
|
|
const mongoose = require('mongoose');
|
2017-05-10 13:36:40 +02:00
|
|
|
mongoose.connect(config.database.uri + config.database.db);
|
2017-05-10 11:04:06 +02:00
|
|
|
const UserModel = require('../../models/user');
|
|
|
|
|
2017-05-10 13:36:40 +02:00
|
|
|
const squads = ['590dd702b899f8050691f09a', '59101b6366d61c085a9f57df',
|
|
|
|
'591025e266d61c085a9f57e1', '591025cf66d61c085a9f57e0', '590d2cf5bd08480bd4ecc128'];
|
2017-05-10 11:04:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* provide number of users to create as argument
|
|
|
|
*/
|
|
|
|
const quantity = process.argv[2];
|
|
|
|
|
|
|
|
|
|
|
|
// CONNECTION EVENTS
|
|
|
|
// When successfully connected
|
|
|
|
mongoose.connection.on('connected', () => {
|
2017-05-10 13:36:40 +02:00
|
|
|
console.log('Mongoose default connection open');
|
2017-05-10 11:04:06 +02:00
|
|
|
});
|
|
|
|
|
2017-05-10 13:36:40 +02:00
|
|
|
const createString = (possible, length) => {
|
|
|
|
let text = "";
|
|
|
|
|
2017-05-11 15:12:17 +02:00
|
|
|
for (let i = 0; i < length; i++)
|
2017-05-10 13:36:40 +02:00
|
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
|
|
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2017-05-10 11:04:06 +02:00
|
|
|
for (let i = 0; i < quantity; i++) {
|
|
|
|
const squadId = squads[Math.floor(Math.random() * squads.length)];
|
|
|
|
|
|
|
|
UserModel.create({
|
|
|
|
username: createString('abcdefghijklmnopqrstuvwxyz0123456789', 10),
|
|
|
|
squadId: squadId,
|
|
|
|
rankLvl: Math.floor(Math.random() * 22)
|
|
|
|
}, function (err, user) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
} else {
|
|
|
|
console.log('User created: ' + user);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the Node process ends, close the Mongoose connection
|
|
|
|
process.on('SIGINT', () => {
|
|
|
|
mongoose.connection.close(function () {
|
|
|
|
console.log('Mongoose default connection disconnected through app termination');
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// process.exit();
|