Created
May 2, 2014 08:20
-
-
Save pratik60/11470055 to your computer and use it in GitHub Desktop.
user migrate
This file contains hidden or 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
| var user_migration_error = []; | |
| function user_migration_save(user) { | |
| user.save(function(err) { | |
| if (err) { | |
| console.log(err); | |
| console.log(user.email); | |
| user_migration_error.push(user); | |
| } | |
| else { | |
| console.log('well done ' + user.email); | |
| } | |
| }); | |
| } | |
| exports.migrate = function(req, res) { | |
| var url = 'http://intranet.xoxo.com/beta/users'; | |
| var users = []; | |
| request(url, function(error, response, html){ | |
| if(!error){ | |
| var data = JSON.parse(response.body); | |
| for(var i in data) { | |
| //console.log(data[i].uid.content); | |
| var user = new User(); | |
| user.provider = 'ldap'; | |
| user.name = data[i].name.content; | |
| user.username = data[i].name.content; | |
| user.email = data[i].mail.content; | |
| user.uid = data[i].uid.content; | |
| //Roles | |
| if (data[i].rid) { | |
| user.roles = data[i].rid.content.split(','); | |
| } | |
| .... | |
| .... | |
| .... | |
| user_migration_save(user); | |
| } | |
| res.jsonp(user_migration_error); | |
| } | |
| }) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to execute this -: res.jsonp(user_migration_error) synchronously ,basically only after the for loop is over
But it gets executed asynchronously, and the users which couldn’t be migrated are not populated on the screen. Things are working perfectly fine in the backend, just the output on the screen is wrong.