Cannot read property 'findAll' of undefined sequelize express JS - javascript

I have a problem with my code when using sequelize auto.
the problem is how to connect sequelize model to database setting on DB.js, so that we can using findall function or any else
Model :
/* jshint indent: 2 */
const db = require('../../db/database')
const sequelize = db.sequelize
module.exports = function(sequelize, DataTypes) {
cust: sequelize.define('ms_customer', {
id: {
type: DataTypes.CHAR(10),
allowNull: false,
primaryKey: true
},
gender_id: {
type: DataTypes.INTEGER(1),
allowNull: true
},
status: {
type: DataTypes.CHAR(1),
allowNull: true
}
}, {
tableName: 'ms_customer'
});
};
DB.js connection :
const Sequelize = require('sequelize')
const sqlz = new Sequelize('db', 'user', 'pass', {
host: 'localhost',
dialect: 'mysql',
pool: {
max: 5,
min: 10,
idle: 10000
}
})
sqlz
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
module.exports = {
sqlz: sqlz,
Sequelize: Sequelize
}
Query :
const customerModel = require('../../db/model/ms_customer')
const cust = customerModel.cust
module.exports = {
modelGetCustomerById : (param,req,res) => {
cust.findAll({
where: {
id: {
param
}
}
}).then(customer => {
// console.log(customer)
res.json(customer)
})
}
}
Controller :
const customer = require('../../db/query/customer')
const sequelize = require('sequelize')
module.exports = {
getCustomerById: async(req,res) => {
var customerId = req.params.id
let getCustomerId = await customer.modelGetCustomerById(customerId)
// console.log(getCustomerId)
if(!getCustomerId){
return res.status(500).json({status: "Failed", message:"User not found"});
}
return res.status(200).json({status: "Success", message:getCustomerId});
}
}
why i always got error
Cannot read property 'findAll' of undefined
please help..

I've running code without error on my project that remodel by sequelize-auto and connect by sequelize. Check it out :
on models/index.js: ( for connection to 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 = sequelize['import'](path.join(__dirname, file));
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;
On models/m_bank.js code :
module.exports = function(sequelize, DataTypes) {
return sequelize.define('m_bank', {
bank: {
type: DataTypes.STRING,
allowNull: false,
defaultValue: '',
primaryKey: true
},
bank_name: {
type: DataTypes.STRING,
allowNull: true
},
address: {
type: DataTypes.STRING,
allowNull: true
},
branch: {
type: DataTypes.STRING,
allowNull: true
},
create_date: {
type: DataTypes.DATE,
allowNull: true
},
update_date: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 'm_bank',
timestamps: false,
schema: 'db_hrms'
});
};
on controllers/m_bank.js
const M_Bank = require('../models').m_bank;
module.exports = {
list(req, res) {
return M_Bank
.findAll()
.then(M_Bank => res.status(200).send(M_Bank))
.catch((error) => {
console.log(error.toString());
res.status(400).send(error)
});
},
getById(req, res) {
return M_Bank
.findById(req.params.id)
.then(M_Bank => {
if (!M_Bank) {
return res.status(404).send({ message: "M_Bank Not Found" });
}
return res.status(200).send(M_Bank);
})
.catch((error) => res.status(400).send(error));
},
add(req, res) {
return M_Bank
.findOrCreate({
where: { bank: req.body.bank },
defaults: {
bank: req.body.bank,
bank_name: req.body.bank_name,
address: req.body.address,
branch: req.body.branch
}
})
.spread((M_Bank, created) => {
return res.status(created === false ? 400 : 200).send({
messsage: "Bank record " + (created === false ? "Already exists" : "successfully added")
})
})
// .then((M_Bank) => { res.status(201).send(M_Bank) })
// .catch((error) => res.status(400).send(error));
},
update(req, res) {
return M_Bank
.findById(req.params.id)
.then(M_Bank => {
if (!M_Bank) {
return res.status(404).send({ message: "Bank Not Found" });
}
return M_Bank
.update({
bank: req.body.bank || M_Bank.bank,
bank_name: req.body.bank_name || M_Bank.bank_name,
address: req.body.address || M_Bank.address,
branch: req.body.branch || M_Bank.branch
})
.then(() => res.status(200).send({
message: "Bank successfully update"
}))
.catch((error) => res.status(400).send({
message: "Bank Not Found"
}));
})
.catch((error) => res.status(400).send({
message: "No parameter for Bank ID"
}));
},
delete(req, res) {
return M_Bank
.findById(req.params.id)
.then((M_Bank) => {
if (!M_Bank) {
return res.status(404).send({ message: "M_Bank Not Found" });
}
return M_Bank
.destroy()
.then(() => res.status(204).send({
message: "Bank record successfully delete"
}))
.catch((error) => res.status(400).send({
message: "Bank Not Found"
}));
})
.catch((error) => res.status(400).send(error));
}
}
on config/config.json configuration code:
{
"development": {
"username": "tihagi",
"password": "123456",
"database": "db_tihagi",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "tihagi",
"password": "123456",
"database": "db_tihagi",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "tihagi",
"password": "123456",
"database": "db_tihagi",
"host": "127.0.0.1",
"dialect": "postgres"
}
}
Hope this can help you.
Note: my db is postgres, please change as per your dialect db.
-Tihagi

Possible reason could be that you didn't pass the model name correctly. What is the output of console.log(cust)

Change your customer model to this one.
/* jshint indent: 2 */
const db = require('../../db/database')
const sequelize = db.sequelize
module.exports = function(sequelize, DataTypes) {
var cust = sequelize.define('ms_customer', {
id: {
type: DataTypes.CHAR(10),
allowNull: false,
primaryKey: true
},
gender_id: {
type: DataTypes.INTEGER(1),
allowNull: true
},
status: {
type: DataTypes.CHAR(1),
allowNull: true
}
}, {
tableName: 'ms_customer'
});
return cust;
};
Your query to
const customerModel = require('../../db/model/ms_customer')
//const cust = customerModel.cust .... you do not need this.
module.exports = {
modelGetCustomerById : (param,req,res) => {
customerModel.findAll({
where: {
id: {
param
}
}
}).then(customer => {
// console.log(customer)
res.json(customer)
})
}
}

Related

Cannot read properties of null (reading 'experience'). after all this i should get profile with all experience .but all time i end up with server err

i was following brad traversy's one of his udemy course. after working on adding experience in profile in profile routes. i all time get server error. but it should end up with full profile details like in brad course. this is my github link for that project
https://github.com/arshad007hossain/findDevs
profile.js
const express = require("express");
const router = express.Router();
const auth = require("../../middleware/authmiddleware");
const { check, validationResult } = require("express-validator");
const Profile = require("../../models/Profile");
const User = require("../../models/User");
// #route GET api/profile/me
// #desc Get current users profile
// #access Private
router.get("/me", auth, async (req, res) => {
try {
const profile = await Profile.findOne({
user: req.user.id,
}).populate("user", ["name", "avatar"]);
if (!profile) {
return res.status(400).json({ msg: "There is no profile for this user" });
}
res.json(profile);
} catch (err) {
console.error(err.message);
res.status(500).send("Server Error");
}
});
// #route POST api/profile/me
// #desc create or update users profile
// #access Private
router.post(
"/",
[
auth,
[
check("status", "status is required").not().isEmpty(),
check("skills", "skills is required").not().isEmpty(),
],
],
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const {
company,
website,
location,
bio,
status,
githubusername,
facebook,
linkedin,
twitter,
instagram,
youtube,
skills,
} = req.body;
//build user profile
const profileFields = {};
profileFields.user = req.user.id;
if (company) profileFields.company = company;
if (website) profileFields.website = website;
if (location) profileFields.location = location;
if (bio) profileFields.bio = bio;
if (status) profileFields.status = company;
if (githubusername) profileFields.githubusername = githubusername;
if (skills) {
profileFields.skills = skills.split(",").map((skill) => skill.trim());
}
//build social objects
profileFields.social = {};
if (youtube) profileFields.social.youtube = youtube;
if (twitter) profileFields.social.twitter = twitter;
if (linkedin) profileFields.social.linkedin = linkedin;
if (instagram) profileFields.social.instagram = instagram;
if (facebook) profileFields.social.facebook = facebook;
//console.log(profileFields.skills);
try {
let profile = await Profile.findOne({ user: req.user.id });
if (profile) {
//Update
profile = await Profile.findOneAndUpdate(
{ user: req.user.id },
{ $set: profileFields },
{ new: true }
);
return res.json(profile);
}
//create
profile = new Profile(profileFields);
await profile.save();
res.json(profile);
} catch (err) {
console.errora(err.message);
res.status(500).json("server error");
}
}
);
// #route GET api/profile
// #desc Get all profile
// #access Public
router.get("/", async (req, res) => {
try {
let profiles = await Profile.find().populate("user", ["name", "avatar"]);
res.json(profiles);
} catch (err) {
console.error(err.message);
res.status(500).json("server error");
}
});
// #route GET api/profile/user/user_id
// #desc Get single profile
// #access Public
router.get("/user/:user_id", async (req, res) => {
try {
const profile = await Profile.findOne({
user: req.params.user_id,
}).populate("user", ["name", "avatar"]);
if (!profile) return res.status(400).json({ msg: "Profile not found" });
res.json(profile);
} catch (err) {
if (err.kind == "ObjectId") {
return res.status(400).json({ msg: "Profile not found" });
}
console.error(err.message);
res.status(500).json("server error");
}
});
// #route DELETE api/profile
// #desc Delete profile, user
// #access Private
router.delete("/", auth, async (req, res) => {
try {
// Remove profile
await Profile.findOneAndRemove({ user: req.user.id });
// Remove user
await User.findOneAndRemove({ _id: req.user.id });
res.json({ msg: "User deleted" });
} catch (err) {
console.error(err.message);
res.status(500).send("Server Error");
}
});
// #route PUT api/profile/experience
// #desc Add profile experience
// #access Private
router.put(
'/experience',
[
auth,
[
check('title', 'Title is required field').not().isEmpty(),
check('company', 'Company is required field').not().isEmpty(),
check('from', 'From date is required field').not().isEmpty(),
],
],
async (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const {
title,
company,
location,
from,
to,
current,
description,
} = req.body;
const newExp = {
title,
company,
location,
from,
to,
current,
description,
};
try {
const profile = await Profile.findOne({ user: req.user.id });
profile.experience.unshift(newExp);
await profile.save();
res.json(profile);
} catch (err) {
console.error(err.message);
res.status(500).send('Server Error');
}
});
module.exports = router;
User.js
const mongoose = require("mongoose");
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
avatar: {
type: String,
},
date: {
type: Date,
default: Date.now,
},
});
module.exports = User = mongoose.model("user", UserSchema);
Profile.js Model
const mongoose = require('mongoose');
const ProfileSchema = new mongoose.Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'user'
},
company: {
type: String
},
website: {
type: String
},
location: {
type: String
},
status: {
type: String,
required: true
},
skills: {
type: [String],
required: true
},
bio: {
type: String
},
githubusername: {
type: String
},
experience: [
{
title: {
type: String,
required: true
},
company: {
type: String,
required: true
},
location: {
type: String
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
],
education: [
{
school: {
type: String,
required: true
},
degree: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
],
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
},
date: {
type: Date,
default: Date.now
}
});
module.exports = mongoose.model('profile', ProfileSchema);

How can i get list of customers between a date range?

How can i get list of customers between a date? There will be a starting date and an ending date picker in my frontend react app, but i dont know how to get the data in a specific date range uisng mongoose in my express app. Im posting my mongoose model and router code below, a little help will be appreciated --
mongoose model
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const customerSchema = new Schema(
{
name: {
type: String,
required: true,
max: 50,
},
phone: {
type: String,
required: true,
max: 12,
},
address: {
type: String,
required: true,
max: 100,
},
pin: {
type: String,
required: true,
max: 6,
},
remarks: {
type: String,
max: 50,
},
isConverted: {
type: Boolean,
default: false,
},
},
{ timestamps: true }
);
const Customer = mongoose.model(
'Customer',
customerSchema
);
module.exports = Customer;
route
const router = require('express').Router();
const Customer = require('../models/Customer');
router.post('/add', (req, res) => {
const newCustomer = new Customer({
name: req.body.name,
phone: req.body.phone,
address: req.body.address,
pin: req.body.pin,
});
newCustomer
.save()
.then((cx) => {
if (!cx) {
res
.status(400)
.send('Error creating a new customer');
} else {
res.send(cx);
}
})
.catch((err) => {
res.status(500).json({ err });
});
});
router.get('/list', (req, res) => {
Customer.find()
.then((cx) => {
if (!cx) {
res
.status(400)
.send('Error getting customer');
} else {
res.send(cx);
}
})
.catch((err) => {
res.status(500).json({ err });
});
});
router.get('/getbyphone/:phone', (req, res) => {
Customer.findOne({ phone: req.params.phone })
.then((cx) => {
if (!cx) {
res
.status(400)
.send('Error getting customer');
} else {
res.send(cx);
}
})
.catch((err) => {
res.status(500).json({ err });
});
});
router.get('/getbyname', (req, res) => {
Customer.findOne({ name: req.body.name })
.then((cx) => {
if (!cx) {
res
.status(400)
.send('Error getting customer');
} else {
res.send(cx);
}
})
.catch((err) => {
res.status(500).json({ err });
});
});
router.put('/:id', (req, res) => {
Customer.findByIdAndUpdate(req.params.id, {
remarks: req.body.remarks,
isConverted: req.body.isConverted,
})
.then((response) => {
res.send('Successfully updated');
})
.catch((err) => {
res.status(500).json({ err });
});
});
router.get('/:id', (req, res) => {
Customer.findById(req.params.id)
.then((cx) => {
res.send(cx);
})
.catch((err) => {
res.status(500).json(err);
});
});
module.exports = router;
add new route like this
router.post('/getByDate', (req, res) => {
Customer.find({ createAt:{$gt: req.body.min,$lt:req.body.max })
.then((cx) => {
if (!cx) {
res
.status(400)
.send('Error getting customer');
} else {
res.send(cx);
}
})
.catch((err) => {
res.status(500).json({ err });
});
});
and send data from front lime this
{
min:mindate,
max:maxdate
}

Sequelize update information

I've been struggling with this issue for a day now and can't seem to figure out a way to resolve it. This is the code I'm running
Client side:
const nameInput = document.querySelector("#nameInput");
const urlInput = document.querySelector("#urlInput");
const rowAlert = document.querySelector(".alertAppend");
const divAlert = document.createElement("div");
const nameUpdate = async (e) => {
e.preventDefault();
fetch("/auth/updateName", {
method: 'POST',
headers: {
'Content-Type' : 'application/json'
},
body: JSON.stringify({
name: nameInput,
url: urlInput,
})
})
.then(function (data) {
console.log('Request success: ', data);
})
.catch(function (error) {
console.log('Request failure: ', error);
});
};
submitName.addEventListener("click", nameUpdate);
API:
router.get("/updateName", auth, async (req, res) =>{
try {
const { name, url } = req.body;
const ime = name;
const uid = req.session.passport.user;
db.User.find({ where: { id: uid } })
.on('success', function (user) {
if (user) {
user.update({
name: ime,
webhook: url
})
.success(function () {})
}
})
res.json({ message: url});
} catch (err) {
if (err) res.status(500).json({ message: "Internal Error"})
}
});
For some reason it just runs the select query and never proceeds to update the user.
Chrome console output
Debug console output
Sequelize model in case it helps:
module.exports = function (sequelize, DataTypes) {
var User = sequelize.define("User", {
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
validate: {
isEmail: true
}
},
password: {
type: DataTypes.STRING,
allowNull: false
},
name: {
type: DataTypes.STRING
}
})
return User;
}
The issue was in the API, it's supposed to be router.post
router.post("/updateName", auth, async (req, res) =>{
const { ime, url } = req.body;
const uid = req.session.passport.user;
console.log(ime);
db.User.findOne({where: {id: uid}})
.then(record => {
let values = {
name: ime,
webhook: url
}
record.update(values).then( updatedRecord => {
console.log(`updated record ${JSON.stringify(updatedRecord,null,2)}`)
res.status(200).json({ message: "success"});
})
}
})
.catch((error) => {
// do seomthing with the error
throw new Error(error)
})
});
You can try the following code
await db.User.update({
name: ime,
webhook: url
}, { where: { id: uid } });
When defining your model I don't see the webhook field

How export and use models in sequelize

i use sequelize in my node.js project, and i dont know how to export and use table model in another file.
I save table models in folder for example Profile.js
module.exports = (sequielize, DataTypes) => sequielize.define('Profile', {
ID: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
Login: {
type: DataTypes.STRING(24),
allowNull: false
},
SocialClub: {
type: DataTypes.STRING(128),
allowNull: false
},
Email: {
type: DataTypes.STRING(64),
allowNull: false
},
RegIP: {
type: DataTypes.STRING(17),
allowNull: false
},
LastIP:
{
type: DataTypes.STRING(17),
allowNull: false
},
RegDate: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
allowNull: false
},
LastDate: {
type: DataTypes.DATE,
defaultValue: DataTypes.NOW,
allowNull: false
}
});
And I have such database module database.js:
const Sequelize = require('sequelize');
const fs = require('fs')
const path = require('path')
const config = require('../configs/server_conf');
db = {};
const sequelize = new Sequelize(
config.db_settings.database,
config.db_settings.user,
config.db_settings.password,
config.db_settings.options);
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.checkConnection = async function() {
sequelize.authenticate().then(() => {
console.log('Подключение к базе данных прошло успешно!');
//import db models
fs.readdirSync(path.join(__dirname, '..', 'models')).forEach(file => {
var model = sequelize.import(path.join(__dirname, '..', 'models', file));
db[model.name] = model;
});
sequelize.sync({
force: true
}).then(() => {
console.log('synchroniseModels: Все таблицы были созданы!');
}).catch(err => console.log(err));
mp.events.call("initServerFiles");
}).catch(err => {
console.error('Невозможно подключиться к базе данных:', err);
});
}
module.exports = db;
And i have such an index.js file where i'm exporting checkConnection function:
"use strict"
const fs = require('fs');
const path = require('path');
const { checkConnection } = require('./modules/database.js');
var Events = [];
mp.events.add(
{
"initServerFiles" : () =>
{
fs.readdirSync(path.resolve(__dirname, 'events')).forEach(function(i) {
Events = Events.concat(require('./events/' + i));
});
Events.forEach(function(i) {
mp.events.add(i);
console.log(i);
});
mp.events.call('initServer');
console.log("Загрузка всех файлов прошла успешно!");
}
});
checkConnection();
So in a nutshell, how i can export my Profile table and use it, for example:
Profile.create({
Login: "0xWraith",
SocialClub: "0xWraith",
Email: "mail#gmail.com",
RegIP: "127.0.0.1",
LastIP: "127.0.0.1",
LastDate: "07.04.2020"
}).then(res => {
console.log(res);
}).catch(err=>console.log(err));
So you already have all registered models in the database.js module. Just import the whole database.js like this:
const db = require('./modules/database.js');
...
db.Profile.create({
Login: "0xWraith",
SocialClub: "0xWraith",
Email: "mail#gmail.com",
RegIP: "127.0.0.1",
LastIP: "127.0.0.1",
LastDate: "07.04.2020"
}).then(res => {
console.log(res);
}).catch(err=>console.log(err));

I can not create a "researcher" using the sequelize

I try to create a new researcher but I just go into catch, and I do not get any errors. I am new using sequelize, I need a lot of help for this problem, my complete code in git: https://github.com/chanudinho/RevYou-BackEnd.
I can't explain it better, please if you need to download the project and test it. Sorry for my english =x
researcherController.js
const Researcher = require('../../sequelize/models/researcher');
const createResearcher= async (req, res) => {
try{
Researcher.create({name: 'name', email: 'email', password: 'password'});
return res.status(201).send('sucesso');
}catch (err){
return res.status(500).send('error');
}
}
models/researcher.js
module.exports = (sequelize, DataTypes) => {
const Researcher = sequelize.define('Researcher', {
name: DataTypes.STRING,
email: DataTypes.STRING,
password: DataTypes.STRING
});
return Researcher;
};
migrations/20190114200431-create-researcher
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Researcher', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
name: {
allowNull: false,
type: Sequelize.STRING
},
email: {
allowNull: false,
type: Sequelize.STRING
},
password:{
allowNull: false,
type: Sequelize.STRING
},
createdAt: {
allowNull: false,
type: Sequelize.DATE
},
updatedAt: {
allowNull: false,
type: Sequelize.DATE
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.dropTable('Researcher');
}
};
models/index.js
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const config = require('../../config/database.js');
const db = {};
const sequelize = new Sequelize(config);
fs
.readdirSync(__dirname)
.filter(file => (file.indexOf('.') !== 0) && (file !== path.basename(__filename)) && (file.slice(-3) === '.js'))
.forEach((file) => {
const model = sequelize.import(path.join(__dirname, file));
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;
The problem is that you are importing the model file and this is not right, your index.js within model maps all model files by adding the sequelize instance and the datatypes. You should always import the index.
If you import the model index and give a console.log() in it will see that you have the object of your model and the instance of the sequelize.
const db = require('../../sequelize/models/index');
console.log(db)
Inside the exit will have something like this: Example:
Researcher: Researcher,
sequelize:
Sequelize { ....
To access your model you can do the following. By using destructuring assignment, you extract the model from within the index.
Result
const { Researcher } = require('../../sequelize/models/index')
const createResearcher= async (req, res) => {
try{
await Researcher.create({name: 'name', email: 'email', password: 'password'});
return res.status(201).send('sucesso')
}catch (err){
return res.status(500).send('error');
}
}
Whenever you create a new file inside the model folder, it will be mapped by index.js and added inside the matrix and using destructuring you can access or use the matrix key itself.
const db = require('../../sequelize/models/index')
const createResearcher= async (req, res) => {
try{
await db.Researcher.create({name: 'name', email: 'email', password: 'password'});
return res.status(201).send('sucesso')
}catch (err){
return res.status(500).send('error');
}
}

Categories

Resources