No Sequelize instance passed for discordjs - mysql

https://github.com/qaiswaz/ticket
hear is the code please help me I've bean searching for a solution for a week now.
every time i try to run the bot hear is what it says
bot is online
Executing (default): SELECT 1+1 AS result
connected to DB
Error: No Sequelize instance passed
at Function.init (C:\Users\qaisw\OneDrive\Desktop\ALL FILES\discording\ticket\node_modules\sequelize\lib\model.js:921:13)
at Function.init (C:\Users\qaisw\OneDrive\Desktop\ALL FILES\discording\ticket\models\TicketConfig.js:5:20)
at C:\Users\qaisw\OneDrive\Desktop\ALL FILES\discording\ticket\bot.js:13:22
at processTicksAndRejections (internal/process/task_queues.js:88:5)
bot.js
require('dotenv').config();
const { Client } = require('discord.js');
const client = new Client({ partials: ['MESSAGE', 'REACTION'] });
const db = require('./database');
const Ticket = require('./models/Ticket');
const TicketConfig = require('./models/TicketConfig');
client.once('ready', () => {
console.log('bot is online');
db.authenticate()
.then(() => {
console.log('connected to DB');
Ticket.init(db);
TicketConfig.init(db);
Ticket.sync();
TicketConfig.sync();
}).catch((err) => console.log(err));
});
client.on('message', async message => {
if (message.author.bot || message.channel.type === 'dm') return;
if (message.content.toLowerCase() ==='?setup' && message.guild.ownerID === message.author.id) {
try {
const filter = (m) => m.author.id === message.author.id;
message.channel.send('please enter the message id for this ticket');
const msgId = (await message.channel.awaitMessages(filter, { max: 1})).first().content;
console.log(msgId)
const fetchMsg = message.channel.messages.fetch(msgId);
message.channel.send('please enter the category id for this ticket');
const categoryId = (await message.channel.awaitMessages(filter, { max: 1})).first().content;
console.log(categoryId)
const categoryChannel = client.channels.catche.get(categoryId);
message.channel.send('please enter all of the roles that have access to tickets');
const roles = (await message.channel.awaitMessages(filter, {max: 1})).first().content.split(/,\s*/);
if (fetchMsg && categoryChannel) {
for (const roleId of roles)
if (!message.guild.roles.cache.get(roleId)) throw new Error('role does not exist');
const ticketConfig = await TicketConfig.create({
messageId: msgId,
guildId: message.guild.id,
roles: json.stringify(roles),
parentId: categoryChannel.id
});
message.channel.send('saved config to db');
}else throw new error('invaild fields');
}catch (err) {
}
}
});
client.login(process.env.BOT_TOKEN);
database.js
const { Sequelize } = require('sequelize');
module.exports = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
dialect: 'mysql',
host: process.env.DB_HOST
});
*models/Ticket.js
const { DataTypes, Model } = require('sequelize');
module.exports = class Tickets extends Model {
static init(sequelize) {
return super.init( {
ticketId: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
channelId: {
type: DataTypes.STRING,
},
guildId: {
type: DataTypes.STRING,
},
resolved:{
type: DataTypes.BOOLEAN,
},
closedMessageId:{
type: DataTypes.STRING,
},
authorId:{
type: DataTypes.STRING,
},
},
{
sequelize: sequelize,
modelName: 'Ticket'
})
}
}
models/TicketConfig.js
const { DataTypes, Model } = require('sequelize');
module.exports = class TicketConfig extends Model {
static init(sequelize) {
return super.init({
messegeId: {
type: DataTypes.STRING,
primaryKey: true
},
guildld: {
type: DataTypes.STRING
},
roles: {
type: DataTypes.STRING
},
parentld: {
type: DataTypes.STRING
},
sequelize: sequelize,
modelName: 'TicketConfig',
})
}
}

I added sequelizeInstance while define model
*models/Ticket.js
const { DataTypes, Model } = require('sequelize');
const sequelizeInstance = require('./database');
module.exports = class Tickets extends Model {
static init(sequelize) {
return super.init( {
ticketId: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
channelId: {
type: DataTypes.STRING,
},
guildId: {
type: DataTypes.STRING,
},
resolved:{
type: DataTypes.BOOLEAN,
},
closedMessageId:{
type: DataTypes.STRING,
},
authorId:{
type: DataTypes.STRING,
},
},
{
sequelize: sequelizeInstance, // <-
modelName: 'Ticket'
})
}
}
models/TicketConfig.js
const { DataTypes, Model } = require('sequelize');
const sequelizeInstance = require('./database')
module.exports = class TicketConfig extends Model {
static init(sequelize) {
return super.init({
messegeId: {
type: DataTypes.STRING,
primaryKey: true
},
guildld: {
type: DataTypes.STRING
},
roles: {
type: DataTypes.STRING
},
parentld: {
type: DataTypes.STRING
},
sequelize: sequelizeInstance, // <-
modelName: 'TicketConfig',
})
}
}

Related

Sequelize role and user relation

I am using nodejs+express, sequelize+mysql stack for RestAPI. I want to get users with it's roles table
models/user.js
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class User extends Model {
static associate(models) {
User.belongsTo(models.Role, {
foreignKey: 'role_id',
as: 'abc'
});
}
}
User.init({
id:{
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
email: DataTypes.STRING,
password: DataTypes.STRING,
role_id: DataTypes.INTEGER,
}, {
sequelize,
modelName: 'User',
});
return User;
};
models/role.js
const { Model } = require('sequelize');
module.exports = (sequelize, DataTypes) => {
class Role extends Model {
Role.hasMany(models.User);
}
}
Role.init({
id:{
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
role_name: DataTypes.STRING
}, {
sequelize,
modelName: 'Role',
});
return Role;
};
controller.js
let users = await User.findAll({
include: {
model: Role,
as: 'role'
}
});
I am getting this error: TypeError: include.model.getTableName is not a function
How should i set this relation?

Graphql using Sequelize + mysql: Database Variable always empty

I have gone through many different solutions to overcome this problem. But nothing seems to be working.
My Files:
database.js
const {Sequelize} = require("sequelize");
var db = {}
const sequelize = new Sequelize('ETconnect', 'root', 'D5kIzmJB', {
host: '10.10.10.11',
port: '3306',
dialect: 'mysql',
define: {
freezeTableName: true,
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
},
// <http://docs.sequelizejs.com/manual/tutorial/querying.html#operators>
operatorsAliases: false,
})
let models = [
require('./models/users.js'),
]
// Initialize models
models.forEach(model => {
const seqModel = model(sequelize, Sequelize)
db[seqModel.name] = seqModel
})
// Apply associations
Object.keys(db).forEach(key => {
if ('associate' in db[key]) {
db[key].associate(db)
}
})
db.sequelize = sequelize
db.Sequelize = Sequelize
exports.db;
models/users.js
const {Sequelize} = require('sequelize');
module.exports = function(sequelize, DataTypes) {
return sequelize.define('users', {
id: {
autoIncrement: true,
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
primaryKey: true
},
name: {
type: DataTypes.STRING(50),
allowNull: false
},
email: {
type: DataTypes.STRING(50),
allowNull: false,
unique: "email"
},
password: {
type: DataTypes.STRING(255),
allowNull: false
},
profileimage: {
type: DataTypes.STRING(45),
allowNull: true
}
}, {
sequelize,
tableName: 'users',
timestamps: false,
indexes: [
{
name: "PRIMARY",
unique: true,
using: "BTREE",
fields: [
{ name: "id" },
]
},
{
name: "email",
unique: true,
using: "BTREE",
fields: [
{ name: "email" },
]
},
]
});
};
models/init-models.js
var DataTypes = require("sequelize").DataTypes;
var _users = require("./users");
function initModels(sequelize) {
var users = _users(sequelize, DataTypes);
return {
users,
};
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;
Graphql/users.js
const {gql} = require("apollo-server-express");
const db = require("../database");
//import { gql } from 'apollo-server-express'
//import * as db from '../database'
exports.typeDefs = gql`
extend type Query {
users: [User]
user(id: ID!): User
}
type User {
id: ID!
name: String
email: String
}
`
exports.resolvers = {
Query: {
users: async () => console.log(db),
user: async (obj, args, context, info) =>
db.users.findByPk(args.id),
},
}
Everytime I use the users query in the Apollo test environment I get a log which says that the Database variable is empty.
Output: {}
Can anybody tell me what I did wrong? Does it not connect to the Database? Because we have a similar application that does perfectly fine.
I would really appreciate the help.

Adding Many to Many Data Sequelize

Case: I have 2 tables; one for users and one for assignments. A user can have many assignments and an assignment can be assigned to many users. I have a form in the frontend to add assignment and assign the users for the assignment and I am really confused on how to add the assignment and user to the joint table 'user_assignment'. Can someone point where I am having the mistake? Also for this, I refer to Advanced M:N Associations.
I also attach my code for the Users and Assignments model, and other relevant code parts.
user.model.js
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define("users", {
firstName: {
type: DataTypes.STRING,
allowNull: false,
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
},
department: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
role: {
type: DataTypes.STRING,
allowNull: false,
},
});
return User;
};
assignment.model.js
module.exports = (sequelize, DataTypes) => {
const Assignment = sequelize.define("assignments", {
title: {
type: DataTypes.STRING,
allowNull: false,
},
department: {
type: DataTypes.STRING,
allowNull: false,
},
urgency: {
type: DataTypes.STRING,
allowNull: false,
},
assignmentBegin: {
type: DataTypes.STRING,
allowNull: false,
},
assignmentEnd: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
});
return Assignment;
};
database/index.js
...
db.user = require("../models/user.model")(sequelize, Sequelize);
db.assignment = require("../models/assignment.model")(sequelize, Sequelize);
...
db.user.belongsToMany(db.assignment, {
through: "user_assignment",
as: "assignments",
foreignKey: "userId",
});
db.assignment.belongsToMany(db.user, {
through: "user_assignment",
as: "users",
foreginKey: "assignmentId",
});
...
assignment.controller.js
const db = require("../database");
const Assignment = db.assignment;
const User = db.user;
exports.create = async (req, res) => {
const {
participant,
title,
department,
urgency,
assignmentBegin,
assignmentEnd,
description,
} = req.body;
await Assignment.create({
title: title,
department: department,
urgency: urgency,
assignmentBegin: assignmentBegin,
assignmentEnd: assignmentEnd,
description: description
}).then(async result => {
for (i = 0; i < participant.length; i++) {
const user = await User.findByPk(participant[i])
// console.log(user.id)
await UserController.addAssignment(user.id, result.id);
// await UserController.addAssignment(2, 1)
}
}).catch(err => {
res.json({ message: "ERROR WHILE CREATING ASSIGNMENT!" });
console.log(">>> ERROR WHILE CREATING ASSIGNMENT!")
});
}
Any pointers on what I should do would be great!
I'd recommend you define the model associations inside each of the model files. Also you should hash/encrypt your passwords before saving them to the DB, you can use the .comparePassword() function outside of the model in a controller when logging in etc.
models/User.js
const Promise = require('bluebird')
const bcrypt = Promise.promisifyAll(require('bcrypt'))
function hashPassword (user) {
const SALT_FACTOR = 12
if (!user.changed('password')) {
return;
} else {
user.setDataValue('password', bcrypt.hashSync(user.password, SALT_FACTOR))
}
}
module.exports = User = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
firstName: {
type: DataTypes.STRING,
allowNull: false,
},
lastName: {
type: DataTypes.STRING,
allowNull: false,
},
department: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
role: {
type: DataTypes.STRING,
allowNull: false,
},
{
hooks: {
beforeCreate: hashPassword,
beforeUpdate: hashPassword
}
})
User.associate = models => {
User."Association type here"(models."Model to associate",
{Options (For many to many add your "through" table here)}
)
// Example:
User.belongsToMany(models.Assignment, {
through: "UserAssignment"
})
}
User.prototype.comparePassword = function (password) {
return bcrypt.compareSync(password, this.password)
}
return User
}
And in the associated Model (models/Assignment.js):
module.exports = Assignment = (sequelize, DataTypes) => {
const Assignment = sequelize.define('Assignment', {
title: {
type: DataTypes.STRING,
allowNull: false,
},
department: {
type: DataTypes.STRING,
allowNull: false,
},
urgency: {
type: DataTypes.STRING,
allowNull: false,
},
assignmentBegin: {
type: DataTypes.STRING,
allowNull: false,
},
assignmentEnd: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
},
{
timestamps: false
})
Assignment.associate = models => {
Assignment.belongsToMany(models.User, {
through: "UserAssignment"
})
}
return Role
}
The joint table (models/UserAssignment.js):
module.exports = UserAssignment = (sequelize, DataTypes) => {
const UserAssignment = sequelize.define('UserAssignment', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
}
},
{
timestamps: false
})
return UserAssignment
}
And finally my index.js file (models/index.js), it programatically adds the models to the DB:
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0)
&& (file !== basename)
&& (file.slice(-3) === '.js');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
As an extra note, you can shorten down your createAssignment function in your controller by doing this instead:
const {
participant,
title,
department,
urgency,
assignmentBegin,
assignmentEnd,
description,
} = req.body;
await Assignment.create({
title: title,
department: department,
urgency: urgency,
assignmentBegin: assignmentBegin,
assignmentEnd: assignmentEnd,
description: description
}).then(async result => {
result.addUsers(participant)
}).catch(err => {
res.json({ message: "ERROR WHILE CREATING ASSIGNMENT!" });
console.log(">>> ERROR WHILE CREATING ASSIGNMENT!")
});
Hope this helps, if not lmk ill try to help some more.

Sequelize include multiple tables in query

So i have the following structure receipts -> policies -> policholders
Every receipt belongs to a policy and every policy belong to a policyholder
What i want to do is when i fetch receipts i get an object back with the both the policy and policyholder included (i am using feathers-sequelize, hook is included below). I get the error that policyholders is not associated to receipts
Desired response:
{
"ReceiptId": 1,
"Supplement": 10.1,
"policy": {
"PolicyNumber": 1234
},
"policyholder": {
"Name": "Joe",
"Surname": "Blogs"
}
}
Policies model
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require("sequelize");
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get("sequelizeClient");
const policies = sequelizeClient.define(
"policies",
{
PolicyId: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
PolicyNumber: {
type: DataTypes.STRING(30),
allowNull: true,
},
CompanyId: {
type: DataTypes.INTEGER,
allowNull: true,
},
PolicyholderId: {
type: DataTypes.INTEGER,
allowNull: true,
},
},
{
hooks: {
beforeCount(options) {
options.raw = true;
},
},
}
);
// eslint-disable-next-line no-unused-vars
policies.associate = function (models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
const { policyholders, companies } = models;
policies.belongsTo(policyholders, { foreignKey: "PolicyholderId" });
};
return policies;
};
Policyholder model
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require("sequelize");
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get("sequelizeClient");
const policyholders = sequelizeClient.define(
"policyholders",
{
PolicyholderId: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
Name: {
type: DataTypes.STRING(250),
allowNull: true,
},
Surname: {
type: DataTypes.STRING(250),
allowNull: true,
},
},
{
hooks: {
beforeCount(options) {
options.raw = true;
},
},
}
);
// eslint-disable-next-line no-unused-vars
policyholders.associate = function (models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
const { policies } = models;
policyholders.hasMany(policies, { foreignKey: "PolicyholderId" });
};
return policyholders;
};
receipts model
// See http://docs.sequelizejs.com/en/latest/docs/models-definition/
// for more of what you can do here.
const Sequelize = require("sequelize");
const DataTypes = Sequelize.DataTypes;
module.exports = function (app) {
const sequelizeClient = app.get("sequelizeClient");
const receipts = sequelizeClient.define(
"receipts",
{
ReceiptId: {
autoIncrement: true,
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
},
PolicyId: {
type: DataTypes.INTEGER,
allowNull: true,
},
Supplement: {
type: DataTypes.INTEGER,
allowNull: true,
},
},
{
hooks: {
beforeCount(options) {
options.raw = true;
},
},
}
);
// eslint-disable-next-line no-unused-vars
receipts.associate = function (models) {
// Define associations here
// See http://docs.sequelizejs.com/en/latest/docs/associations/
const { policies } = models;
receipts.belongsTo(policies, { foreignKey: "PolicyId" });
};
return receipts;
};
get related hook
module.exports = function (options = {}) {
return async (context) => {
const { include, ...query } = context.params.query;
const Policies = context.app.services.policies.Model;
const Policyholders = context.app.services.policyholders.Model;
context.params.sequelize = {
include: [Policies, Policyholders],
raw: false,
};
// Update the query to not include `include`
context.params.query = query;
return context;
};
};
If Placeholders is linked to Receipts through Policies then you need to indicate Placeholders in an include option of Policies itself:
context.params.sequelize = {
include: [{
model: Policies,
include: [Policyholders]
}],
raw: false,
};

Sequelize: Unhandled rejection TypeError: Cannot read property 'id' of undefined

Currently using ExpressJS as the framework to create a small CMS system but currently running into a problem. I am trying to create a model for a table called 'roles' but when I add it to my database file to be included, I get the following error once I run 'node app.js'
Unhandled rejection TypeError: Cannot read property 'id' of undefined
at Object.mapValueFieldNames (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\sequelize\lib\utils.js:232:19)
at Promise.try.then.then (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\sequelize\lib\model.js:2393:37)
at tryCatcher (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\async.js:138:12)
at _drainQueue (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\async.js:131:9)
at Async._drainQueues (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\async.js:147:5)
at Immediate.Async.drainQueues (C:\Users\Ryahn\Documents\Projects\monkeys\node_modules\bluebird\js\release\async.js:17:14)
at runCallback (timers.js:810:20)
at tryOnImmediate (timers.js:768:5)
at processImmediate [as _immediateCallback] (timers.js:745:5)
If I do not include the model in the database init file, it runs just fine. The idea is to then use a relationship to pair the two. I do not plan on having permissions assigned, just using roles. The migration file is setup the same as the model. I was assuming by matching how the user model was setup, the roles model would work as well. But now I am unsure what is going on.
Users
'use strict';
const
Promise = require('bluebird'),
bcrypt = Promise.promisifyAll(require('bcrypt'))
;
module.exports = (sequelize, DataTypes) => {
const users = sequelize.define('users', {
id: {
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
username: {
type: DataTypes.STRING,
notEmpty: true,
unique: true
},
password: {
type: DataTypes.STRING,
notEmpty: true
},
role: {
type: DataTypes.INTEGER(2).UNSIGNED,
validate: {
isNumeric: true
}
},
steamid: {
type: DataTypes.STRING(17),
validate: {
len: 17
}
},
link: {
type: DataTypes.STRING,
validate: {
isUrl: true
}
},
last_login: DataTypes.DATE
},
{
hooks: {
beforeCreate: function(user, options) {
if (!user.changed('password')) {
return sequelize.Promise.reject('not modified');
}
return bcrypt.hash(user.password, 10).then(hash => {
return user.password = hash;
}).catch(err => {
return sequelize.Promise.reject(err);
});
},
beforeUpdate: function(user, options) {
if (!user.changed('password')) {
return sequelize.Promise.reject('not modified');
}
return bcrypt.hash(user.password, 10).then(hash => {
return user.password = hash;
}).catch(err => {
return sequelize.Promise.reject(err);
});
}
}
});
users.prototype.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(10));
};
users.prototype.validPassword = function(password) {
return bcrypt.compareSync(password, this.password);
};
users.sync({force: false}).then(() => {
return users.findOrCreate({
where: {
id: 1,
username: 'Admin'
},
defaults: {
username: 'Admin',
password: 'admin123',
role: 1,
steamid: parseInt(12345678901234567),
link: 'https://www.example.com/user_profile.php?userID=1171981'
}
});
});
return users;
};
Roles
'use strict';
module.exports = (sequelize, DataTypes) => {
const roles = sequelize.define('roles', {
id: {
autoIncrement: true,
primaryKey: true,
type: DataTypes.INTEGER
},
name: DataTypes.STRING,
slug: DataTypes.STRING
}, {
timestamps: false
});
let role = [];
role.push([
{ name: 'Admin', slug: 'admin'},
{ name: 'Staff', slug: 'staff'},
{ name: 'Trainer', slug: 'trainer'},
{ name: 'Captain', slug: 'captain'},
{ name: 'Monkey', slug: 'monkey'}
]);
roles.sync({force: false}).then(() => {
return roles.bulkCreate(role);
});
return roles;
};
Init
const
config = require('../config/database'),
Sequelize = require('sequelize'),
sequelize = new Sequelize(config),
db = {}
;
db.Sequelize = Sequelize;
db.sequelize = sequelize;
db.users = require('./models/users')(sequelize, Sequelize);
db.roles = require('./models/roles')(sequelize, Sequelize);
module.exports = db;