Saturday, 27 May 2017

SequelizeJS Error: TypeError: User.findAll is not a function

I am using sequelizejs with expressjs app.

here is the code of my user model.

user.js

module.exports = function(sequelize, DataTypes) {
  var User = sequelize.define('User', {
    first_name: DataTypes.STRING,
    last_name: DataTypes.STRING,
    bio: DataTypes.STRING,
    email: DataTypes.STRING,
    profile_picture: DataTypes.STRING
  }, {
    classMethods: {
      associate: function(models) {
        // associations can be defined here
      }
    }
  }, {
    tableName: 'users'
  });
  return User;
};

Here is my user controller

userComponent.js

const express = require( 'express' )
const router  = express.Router()
const User    = require( '../../models/user' )

router.get( '/user', ( req, res, next ) => {
  User.findAll()
    .then( userResponse => {
      res.status( 200 ).json( userResponse )
    } )
    .catch( error => {
      res.status( 400 ).send( error )
    } )
} )

module.exports = router

But when i am trying to get the data it throws this errors:

TypeError: User.findAll is not a function at router.get (D:\StateBoard-Project\v2\components\user\userComponent.js:6:8) at Layer.handle [as handle_request] (D:\StateBoard-Project\v2\node_modules\express\lib\router\layer.js:95:5) at next (D:\StateBoard-Project\v2\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\StateBoard-Project\v2\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\StateBoard-Project\v2\node_modules\express\lib\router\layer.js:95:5) at D:\StateBoard-Project\v2\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\StateBoard-Project\v2\node_modules\express\lib\router\index.js:335:12) at next (D:\StateBoard-Project\v2\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\StateBoard-Project\v2\node_modules\express\lib\router\index.js:174:3) at router (D:\StateBoard-Project\v2\node_modules\express\lib\router\index.js:47:12)

enter image description here

What is missing here?



via rakibtg

No comments:

Post a Comment