Skip to content

Instantly share code, notes, and snippets.

@robwormald
Forked from Samstiles/bootstrap.js
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/ae9131ed1a389fe87b94 to your computer and use it in GitHub Desktop.
Save robwormald/ae9131ed1a389fe87b94 to your computer and use it in GitHub Desktop.
//bluebird promise lib >>>> anything
var q = require('bluebird');
module.exports.bootstrap = function(cb) {
//returns a promise
var findOrCreateForm = function(){
return Form.find().then(function(forms){
if(forms.length > 0){
return forms;
}
return Form.create();
})
}
var findOrCreateOrgs = function(){
return Organization.find().then(function(orgs){
if(orgs.length >0){
return orgs;
}
return getOrganizations().map(function(org){
return Organization.create(org);
})
})
}
q.all([findOrCreateForm,findOrCreateOrgs]).then(function(forms,orgs){
cb();
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment