var User = require('../models/user');
var Dog = require('../models/dog');

// is this needed for user
var usersController = {

  createUser: function (req, res) {
    var id = req.body.id;
    var accessToken = req.body.access_token;
    var firstName = req.body.firstName;
    var lastName = req.body.lastName;
    var email = req.body.email;


    User.create({
      id: id,
      accessToken: accessToken,
      firstName: firstName,
      lastName: lastName,
      email: email,
      lostDogs: [{

      }],
       foundDogs: [{

       }]
    },
    function (err, user) {
      if (err) {
        res.status(500).send();
      } else {
        res.status(201).send(JSON.stringify(user));
      }
    });
  },

    show: function (req, res) {
      var id = req.params.id;
      User.findById({_id: id}, function(err, user){
        if (err){
          console.log("There was an error : " + err);
        } else {
          var usersDogs = [];
          // pups.push(Dog.findById(user.dogs[0]));
          user.dogs.forEach(function (query, index) {
            Dog.findById({_id: user.dogs[index]}, function(err, dog){
              console.log(dog);
              usersDogs.push(dog);
              // with console.log here, it shows the value of usersDogs when the surrounding function as a callback.
              console.log(dogs);
            });
          });
          // with console.log here, it'll be executed before the callback is called #FunctionalProgramming o(^_-)O
          // console.log(dogs);
          res.render('users/show', {userShow: user, user: req.user, dog: dogs});

        }
    });

}

};

module.exports = usersController;

@@ -928,25 +928,24 @@
     var user
-s
 Dogs = %5B%5D;%0A 
@@ -943,16 +943,16 @@
 s = %5B%5D;%0A
+
         
@@ -1165,25 +1165,24 @@
         user
-s
 Dogs.push(do
@@ -1251,17 +1251,16 @@
  of user
-s
 Dogs whe
@@ -1319,33 +1319,37 @@
     console.log(
-d
+userD
 ogs);%0A          
@@ -1588,17 +1588,21 @@
 r, dog: 
-d
+userD
 ogs%7D);%0A%0A

clean up naming issues.