title: MEAN Stack, Updating the user from a different module
body: <p>I have a problem with updating/saving users after running a client-side function that adds on a _id (of another module called course) to the user. An overview of what I have is a CRUD module called courses, and I would like for a user to be able to join that course, so the function to do so is as follows 
  (courses.client.controller.js):</p>
  
  <pre><code>    $scope.joinCourse = function() {
  
          var course = $scope.course;
          var user = $scope.authentication.user; 
          var flag = false;
          if ($scope.insertedCCode === course.courseCode) {
              for (var i in user.joinedCourses) {
                  if (user.joinedCourses[i] === course._id) {
                      flag = true;  // Already joined the course
                  }
              }
              if (!flag) {
                  user.joinedCourses.push(course._id);
              }
              course.$updateUser(function(response) {
                  $scope.success = true;
                  Authentication.user = response;
              }, function(response) {
                  $scope.error = response.data.message;
              });
      }
  </code></pre>
  
  <p>updateUser is a server-side function I made to save the new changes made to user, though I am not sure if that is a proper way of adding or using back-end functions. It's the exact same thing as when updating for a profile change. I found that it saves the course if I update my profile after joining the course.</p>
  
  <pre><code>exports.updateUser = function(req, res) {
  // Init Variables
  var user = req.user;
  var message = null;
  
  // For security measurement we remove the roles from the req.body object
  delete req.body.roles;
  
  if (user) {
      // Merge existing user
      user = _.extend(user, req.body);
      user.updated = Date.now();  // Join date??
  
      user.save(function(err) {
          if (err) {
              return res.status(400).send({
                  message: errorHandler.getErrorMessage(err)
              });
          } else {
              req.login(user, function(err) {
                  if (err) {
                      res.status(400).send(err);
                  } else {
                      res.json(user);
                  }
              });
          }
      });
  } else {
      res.status(400).send({
          message: 'User is not signed in'
      });
  }};
  </code></pre>
  
  <p>When I run the joinCourse function, it gives an error of TypeError: undefined is not a function at Scope.$scope.joinCourse, at the line where course.$updateUser is called (from block 1). So I passed in the same things as user.$update needs, why does it not work?</p>
  
  <p>To boil it all down, I'm trying to update a user from a different module and I'm not sure on how to do that.</p>
  
  <p>Any help would be greatly appreciated!</p>