Advertisement
fmunoz92

Untitled

Sep 15th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. exports.fillApps= function(req, res){
  2.  
  3. function fillApp(app) {
  4. var deferred = Q.defer();
  5. App.findOne({name: app.name}, function (err, app) {
  6. if (err) {
  7. return deferred.reject(err);
  8. logger.error('error funding app', err);
  9. }
  10. //logger.debug(app);
  11.  
  12. if (app) {
  13. app.stripeID = app.stripeID || null;
  14. app.imageUrl = app.imageUrl || null;
  15. app.monthlyPrice = app.monthlyPrice || null;
  16. app.status = app.status || null;
  17. app.category = app.category || null;
  18. app.learnMore = app.learnMore || null;
  19. app.visibleBy = app.visibleBy || null;
  20. app.descriptions = app.descriptions || null;
  21. app.tag = app.tag || null;
  22. app.features =app.features || null;
  23. app.save(function (err, app) {
  24. if (err) logger.error('error chargin app', err);
  25. logger.debug('fill with ' + app.name);
  26. deferred.resolve();
  27. });
  28. } else {
  29. var newApp = new App(app);
  30. //logger.debug(tmpIndex);
  31. newApp.save(function (err, app) {
  32. if (err) logger.error('error chargin app', err);
  33. deferred.resolve();
  34. });
  35. }
  36. });
  37.  
  38. return deferred.promise;
  39. }
  40. var promises = [];
  41. for(var cApps = 0; cApps < maxApps; cApps++) {
  42. var p = fillApp(MockApps[cApps]);
  43. promises.push(p);
  44. }
  45. Q.all(promises).then(function() {
  46. res.send(...)
  47. }, function(err) {
  48. res.send(..)
  49. })
  50. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement