0

This is my model.

UserApiSchema.statics.createApi = function(user,fn){
  var instance = new UserApi();
  instance.user = user;
  instance.apiKey = "asdasdacasdasasd";
  console.log("username is " + user.username);
  instance.save(function(err){
    fn(err,instance);
  });
};

UserSchema.statics.newUser = function (email, password,username, fn) {
    var instance = new User();
    var apiInstance = new UserApi();
    instance.email = email;
    instance.password =password;
    instance.username = username;

    instance.save(function (err) {
        fn(err, instance);
    });
};

This is my controller-users.js:

app.post( '/signup/', function(req, res) { {console.log(req.body.username); User.newUser(

            req.body.email, req.body.password,req.body.username,
            function (err, user) {
                if ((user)&&(!err)) {
                    console.log(user.username)

                    UserApi.createApi(
                            user,function(err,userapi){
                                if((!err)){
                                    res.send("APi created")
                                }
                                else{
                                    if(err.errors.apiKey){
                                        res.send(err)
                                    }
                                }


                            });
                    req.session.regenerate(function(){
                        req.session.user = user._id;
                        res.send("Success here!"); 

                    });
                } else {
                    if (err.errors.email) {
                          res.send(err) 
                          console.log(req.body.password);
                          console.log(req.body.email);
                          console.log(req.body);
                        }                           
                   if (err.errors.username) {
                      res.send(err) 
                      console.log(req.body.password);
                      console.log(req.body.email);
                      console.log(req.body);
                    }   
                }
            });


    } 
});

The concept is once the user-name/password is accepted, an API key is stored along with the username. Though, the username payload is getting accepted, when I do the UserApiSchema call to generate the api, no such api is generated. No errors either.

1 Answer 1

1

Might be real basic ... but, did you create the objects needed?

  • UserApiSchema = {};
  • UserApiSchema.statics = {};
  • UserApiSchema.statics.createApi = function(user,fn){ ...}

If so ... are they in a module? Did you export them from the module?

  • exports.userApiSchema = UserApiSchema;

Did you import them in controller-users.js?

  • var userApiSchema = require('./UserApiSchema.js');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.