Skip to content

How to update database? #1051

Description

Hi, I'm new to use angular-fullstack, and now I'm studying and developing using angular-fullstack.

I'm trying to update a field but I went something wrong I think, so I want to ask a question.

I added a field 'introduction' in a collection 'Users' at user.model.Schema
I referenced 'changePassword' method, I made 'changeIntroduction' method.

But it doesn't update the database and I got error
User.changeIntroduction is not a function at Object.Auth.changeIntroduction

Below is my code:

server/api/user/user.controller.js

exports.changeIntroduction = function(req, res) {
  var userId = req.user._id;
  var newIntroduction = String(req.body.newIntroduction);

  User.findById(userId, function (err, user) {
    user.introduction = newIntroduction;
    user.save(function(err) {
      if (err) return validationError(res, err);
      res.send(200);
    });
  })
};

server/api/auth/auth.service.js

      changeIntroduction: function(newIntroudction, callback) {
        var cb = callback || angular.noop;

        return User.changeIntroduction({ id: currentUser._id }, {
          newIntroduction: newIntroudction
        }, function(user) {
          return cb(user);
        }, function(err) {
          return cb(err);
        }).$promise;
      },

server/api/user/index.jsp, I added this router.

router.put('/:id/introduction', auth.isAuthenticated(), controller.changeIntroduction);

I'm sorry for elementary question, but it is hard for me.
If you think this is too elementary, then just let me know any link where I can find some tips.
Thank you very much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions