When attempting to search for all users using the findAll method, I encountered an error message stating: "Cannot read property 'findAll' of undefined."
This issue was identified while working on user.js
var user = require("../../models/user");
var sequelize = require('sequelize');
var constants = require("../../config/constants");
var requestHelper = require("../../helpers/request");
var responseHelper = require("../../helpers/response");
var model = require("../../models");
var main = {
title: "Hello World",
statusCode: constants.HTTP.CODES.SUCCESS
}
main.signup = function (req, res, next) {
var postBody = requestHelper.parseBody(req.body); //requestHelper converts into json format
var responseBody = {};
if (postBody.name != null && postBody.password != null) {
model.user.findAll().then(function (emp) { // finding user
//...........working......//
});
}
});
}
}
module.exports = main;
Upon further investigation by utilizing console.log(model.user), it revealed that the model.user is undefined. The root cause behind this problem remains unidentified.
`'use strict';
module.exports = function(sequelize, DataTypes) {
var user = sequelize.define('User', {
name: DataTypes.STRING,
password: DataTypes.STRING
}, {
classMethods: {
associate: function(models) {
// associations can be defined here
}
}
});
return user;
};
`