2016-09-08 4 views
0

APIメソッドを呼び出すと、「ユーザーは関数ではありません」という同じエラーが発生します。パスポートユーザーが関数ではありません

誰にもこれがなぜ起こっているのかも知れません。

APIメソッド:

//need to export the api methods. 
 
var User = require('../models/user'); 
 
var passport = require('passport'); 
 

 
module.exports.create = function(req, res) { 
 
    //TODO: error checking. 
 
    var user = new User(); 
 
    console.log(req); 
 
    user.firstName = req.body.firstName; 
 
    user.secondName = req.body.secondName; 
 
    user.email = req.body.email; 
 

 
    user.setPassword(req.body.password); 
 

 
    user.save(function(err) { 
 
    res.status(200); 
 
    }); 
 
};

ユーザモデル:

var mongoose = require('mongoose'); 
 
var crypto = require('crypto'); 
 

 
var userSchema = new mongoose.Schema({ 
 
    email: { 
 
    type: String, 
 
    unique: true, 
 
    required: true 
 
    }, 
 
    firstName: { 
 
    type: String, 
 
    required: true 
 
    }, 
 
    lastName: { 
 
    type: String, 
 
    required: true 
 
    }, 
 
    hash: String, 
 
    salt: String 
 
}); 
 

 
userSchema.methods.setPassword = function(password){ 
 
}; 
 

 
userSchema.methods.validPassword = function(password) { 
 
}; 
 

 
mongoose.model('User', userSchema);

私はこれ以上のファイルを入力する必要があるなら、私に教えてください。あなたはユーザーモデルファイルの末尾に作成されたマングースモデルをエクスポートする必要があり

おかげ

+0

あなたのような何かがあなたのUserモデル – Hamms

+0

mongoose.export.model( 'ユーザー'、userSchema)をエクスポートするように見えませんか? – SwimmingG

答えて

1

module.exports = mongoose.model('User', userSchema);

関連する問題