Created
April 1, 2014 00:37
-
-
Save nate-strauser/9905445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.startup(function () { | |
if(!Meteor.roles.findOne({name: "admin"})) | |
Roles.createRole("admin"); | |
if(!Meteor.roles.findOne({name: "baker"})) | |
Roles.createRole("baker"); | |
if(Users.find().count() === 0){ | |
log.info('no users detected, loading sample data'); | |
var newUser = function(username, role){ | |
var userId = Accounts.createUser({ | |
username:username, | |
email:username+'@comp.co', | |
password:'pass' | |
}); | |
log.info('created new user ' + username + ' - ' + userId); | |
if(role === 'admin') | |
Roles.addUsersToRoles(userId, role); | |
if(role === 'baker') | |
{ | |
var bakerId = Bakers.insert({userId:userId,description:'description',name:'John Doe-'+username}); | |
//Users.update({_id:userId},{$set:{bakerId:bakerId}}); | |
log.info('created new baker ' + username + ' - ' + bakerId); | |
} | |
return userId; | |
}; | |
newUser('devadmin','admin'); | |
for(i = 1; i <= 5; i++){ | |
var userId = newUser('devbaker'+i,'baker'); | |
var user = Users.findOne({_id:userId}); | |
if(user){ | |
var bakerId = user.profile.bakerId; | |
for(x = 1; x <= 10; x++){ | |
Products.insert({userId:userId, bakerId:bakerId, title:'product ' + x, description:'description'}); | |
} | |
} | |
} | |
for(i = 1; i <= 10; i++) | |
newUser('devuser'+i); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment