2
// finding users
find: function (req, res, next) {
var userId = req.body.userId;
var userSchema = db.UserModel;
try {
db.sequelize.sync().then(function (params) {
userSchema.findAll({where:{userId:userId}}).then(function (user) {
return res.json({
success:true,
userData:user.get({
plain:true
})
});
});
});
} catch (ex) {
res.json({
success: false,
exception: ex
});
return;
}
}
我書面方式簡單的CRUD API爲我的項目。 而上面提到的執行代碼,我收到錯誤我的控制檯上爲:
Executing (default): SELECT
userId
,firstname
,lastname
,createdAt
,updatedAt
FROMUsers
ASUser
WHEREUser
.userId
= '1'; Unhandled rejection TypeError: Cannot read property 'get' of undefined at D:\tecsol\mtv\api\controllers\UserController.js:52:27 at processImmediate [as _immediateCallback] (timers.js:367:17)