function()

in app/api-service-broker/app.js [157:196]


      function(cb) {
        Rate.count({})
          .then(function(total) {
            console.log(`Ratings present: `, total);
            if (total === 0) {
              var ratingDocs = [];
              async.each(newHeroes, function(hero, writecb) {
                for (var i = 0; i < 21; i++) {
                  var newRating = new Rate({
                    rating: Math.floor(Math.random() * 5) + 1,
                    raterIp: `8.8.4.4`, // using g dns for now
                    heroRated: hero._id
                  });
                  ratingDocs.push(newRating);
                  if (i === 20) {
                    Rate.create(ratingDocs)
                      .then(function(docs) {
                        console.log(`Inserted Ratings Count: `, docs.length);
                        return null;
                      })
                      .catch(function(err) {
                        console.log(`Error creating ratings: `, err);
                      })
                      .finally(function() {
                        writecb();
                      });
                  }
                }
              });
            }
            return null;
          })
          .catch(function(err) {
            console.log(err);
          })
          .finally(function() {
            return null;
            cb(null);
          });
      }