I am new to node js and I generated the models using sequelize-auto
I am encountering this error when I follow the recommendation of this link https://github.com/sequelize/sequelize-auto . if you i need more explanation
please here are my codes
my controller
var jwtutils = require ('../util/jwt');
var db = require ('../routes/bd');
const multer = require ('multer');
var jwt = require ('jsonwebtoken');
const base64 = require ('node-base64-image');
const mime = require ('mime');
const base64Img = require ('base64-img');
var initModels = require("../models/init-models");
var models = initModels(sequelize);
exports.get_publication = function (req, res) {
models.publications
.findAll ({
where: {
$and: [
{'$users.ID_USER$': '$publications.ID_USER$'},
{'$publications.ID_QUARTIER$': '$quartiers.ID_QUARTIER$'},
{'$publications.ID_PRODUIT$': '$produits.ID_PRODUIT$'},
{'$publications.ID_TYPE_PUB$': '$type_pub.ID_TYPE_PUB$'},
{'$publications.ID_TYPE$': '$type_produits.ID_TYPE$'},
{'$publications.ID_PUBLICATION$': '$images_pub.ID_PUBLICATION$'},
],
},
include: [
{
model: users,
required: false,
},
{
model: pays,
required: false,
},
{
model: produits,
required: false,
},
{
model: type_pub,
required: false,
},
{
model: images_pub,
required: false,
},
],
})
.then (data_pub => {
return res.json ({
statut: true,
data_pub: data_pub,
});
})
.catch (function (err) {
console.log (err);
});
};
my models publications
const Sequelize = require('sequelize');
module.exports = function(sequelize, DataTypes) {
return sequelize.define('publications', {
ID_PUBLICATION: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true
},
ID_PRODUIT: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'produits',
key: 'ID_PRODUIT'
}
},
ID_USER: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'users',
key: 'ID_USER'
}
},
ID_QUARTIER: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'quartiers',
key: 'ID_QUARTIER'
}
},
ID_TYPE_PUB: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'type_pub',
key: 'ID_TYPE_PUB'
}
},
CONTENU_PUB: {
type: DataTypes.TEXT,
allowNull: false
},
TITRE_PUB: {
type: DataTypes.STRING(255),
allowNull: false
},
PRIX_PRODUIT: {
type: DataTypes.DECIMAL(11,0),
allowNull: false
},
NOMBRE_PIECE: {
type: DataTypes.INTEGER,
allowNull: false
},
SUPERFICIE: {
type: DataTypes.DECIMAL(11,0),
allowNull: false
},
ETAT_PUB: {
type: DataTypes.BOOLEAN,
allowNull: false
},
DATE_PUB: {
type: DataTypes.DATE(6),
allowNull: false,
defaultValue: "current_timestamp(6)"
},
DATE_MODIF_PUB: {
type: DataTypes.DATE(6),
allowNull: false,
defaultValue: "current_timestamp(6)"
}
}, {
sequelize,
tableName: 'publications',
timestamps: false,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "ID_PUBLICATION" },
]
},
{
name: "I_FK_PUBLICATIONS_PRODUITS",
using: "BTREE",
fields: [
{ name: "ID_PRODUIT" },
]
},
{
name: "I_FK_PUBLICATIONS_USERS",
using: "BTREE",
fields: [
{ name: "ID_USER" },
]
},
{
name: "I_FK_PUBLICATIONS_QUARTIERS",
using: "BTREE",
fields: [
{ name: "ID_QUARTIER" },
]
},
{
name: "I_FK_PUBLICATIONS_TYPE_PUB",
using: "BTREE",
fields: [
{ name: "ID_TYPE_PUB" },
]
},
]
});
};
init-model file
var DataTypes = require("sequelize").DataTypes;
var _commentaires = require("./commentaires");
var _images_pub = require("./images_pub");
var _localite = require("./localite");
var _notifications = require("./notifications");
var _pays = require("./pays");
var _produits = require("./produits");
var _publications = require("./publications");
var _quartiers = require("./quartiers");
var _regions = require("./regions");
var _roles = require("./roles");
var _type_pub = require("./type_pub");
var _users = require("./users");
function initModels(sequelize) {
var commentaires = _commentaires(sequelize, DataTypes);
var images_pub = _images_pub(sequelize, DataTypes);
var localite = _localite(sequelize, DataTypes);
var notifications = _notifications(sequelize, DataTypes);
var pays = _pays(sequelize, DataTypes);
var produits = _produits(sequelize, DataTypes);
var publications = _publications(sequelize, DataTypes);
var quartiers = _quartiers(sequelize, DataTypes);
var regions = _regions(sequelize, DataTypes);
var roles = _roles(sequelize, DataTypes);
var type_pub = _type_pub(sequelize, DataTypes);
var users = _users(sequelize, DataTypes);
quartiers.belongsTo(localite, { as: "ID_LOCALITE_localite", foreignKey: "ID_LOCALITE"});
localite.hasMany(quartiers, { as: "quartiers", foreignKey: "ID_LOCALITE"});
regions.belongsTo(pays, { as: "ID_PAYS_pay", foreignKey: "ID_PAYS"});
pays.hasMany(regions, { as: "regions", foreignKey: "ID_PAYS"});
publications.belongsTo(produits, { as: "ID_PRODUIT_produit", foreignKey: "ID_PRODUIT"});
produits.hasMany(publications, { as: "publications", foreignKey: "ID_PRODUIT"});
commentaires.belongsTo(publications, { as: "ID_PUBLICATION_publication", foreignKey: "ID_PUBLICATION"});
publications.hasMany(commentaires, { as: "commentaires", foreignKey: "ID_PUBLICATION"});
images_pub.belongsTo(publications, { as: "ID_PUBLICATION_publication", foreignKey: "ID_PUBLICATION"});
publications.hasMany(images_pub, { as: "images_pubs", foreignKey: "ID_PUBLICATION"});
notifications.belongsTo(publications, { as: "ID_PUBLICATION_publication", foreignKey: "ID_PUBLICATION"});
publications.hasMany(notifications, { as: "notifications", foreignKey: "ID_PUBLICATION"});
publications.belongsTo(quartiers, { as: "ID_QUARTIER_quartier", foreignKey: "ID_QUARTIER"});
quartiers.hasMany(publications, { as: "publications", foreignKey: "ID_QUARTIER"});
localite.belongsTo(regions, { as: "ID_REGION_region", foreignKey: "ID_REGION"});
regions.hasMany(localite, { as: "localites", foreignKey: "ID_REGION"});
users.belongsTo(roles, { as: "ID_ROLE_role", foreignKey: "ID_ROLE"});
roles.hasMany(users, { as: "users", foreignKey: "ID_ROLE"});
publications.belongsTo(type_pub, { as: "ID_TYPE_PUB_type_pub", foreignKey: "ID_TYPE_PUB"});
type_pub.hasMany(publications, { as: "publications", foreignKey: "ID_TYPE_PUB"});
commentaires.belongsTo(users, { as: "ID_USER_user", foreignKey: "ID_USER"});
users.hasMany(commentaires, { as: "commentaires", foreignKey: "ID_USER"});
notifications.belongsTo(users, { as: "ID_USER_user", foreignKey: "ID_USER"});
users.hasMany(notifications, { as: "notifications", foreignKey: "ID_USER"});
publications.belongsTo(users, { as: "ID_USER_user", foreignKey: "ID_USER"});
users.hasMany(publications, { as: "publications", foreignKey: "ID_USER"});
return {
commentaires,
images_pub,
localite,
notifications,
pays,
produits,
publications,
quartiers,
regions,
roles,
type_pub,
users,
};
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;
error
E:Mes CoursMes projetProjet nodeJSImmoMarketControllersPubController.js:9
var models = initModels(sequelize);
^
ReferenceError: sequelize is not defined
at Object. (E:Mes CoursMes projetProjet nodeJSImmoMarketControllersPubController.js:9:25)