Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.fillApps= function(req, res){
- function fillApp(app) {
- var deferred = Q.defer();
- App.findOne({name: app.name}, function (err, app) {
- if (err) {
- return deferred.reject(err);
- logger.error('error funding app', err);
- }
- //logger.debug(app);
- if (app) {
- app.stripeID = app.stripeID || null;
- app.imageUrl = app.imageUrl || null;
- app.monthlyPrice = app.monthlyPrice || null;
- app.status = app.status || null;
- app.category = app.category || null;
- app.learnMore = app.learnMore || null;
- app.visibleBy = app.visibleBy || null;
- app.descriptions = app.descriptions || null;
- app.tag = app.tag || null;
- app.features =app.features || null;
- app.save(function (err, app) {
- if (err) logger.error('error chargin app', err);
- logger.debug('fill with ' + app.name);
- deferred.resolve();
- });
- } else {
- var newApp = new App(app);
- //logger.debug(tmpIndex);
- newApp.save(function (err, app) {
- if (err) logger.error('error chargin app', err);
- deferred.resolve();
- });
- }
- });
- return deferred.promise;
- }
- var promises = [];
- for(var cApps = 0; cApps < maxApps; cApps++) {
- var p = fillApp(MockApps[cApps]);
- promises.push(p);
- }
- Q.all(promises).then(function() {
- res.send(...)
- }, function(err) {
- res.send(..)
- })
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement