Reputation: 1
I'm using sequelize in my project, and importing the Job(variable connected to the database) from the models folder, but when I use Job.create it returns this error when inserting data into postman: TypeError: Job.create is not a function
I checked the connection with the database, and it's working, but Job.create doesn't work. code:
**//in models at Jobs.js file**
const Sequelize = require('sequelize');
const db = require('../db/connection');
//Define
const Job = db.define('job', {
title:{
type: Sequelize.STRING,
},
description:{
type: Sequelize.STRING
},
salary:{
type: Sequelize.STRING
},
company:{
type: Sequelize.STRING
},
email:{
type: Sequelize.STRING
},
new_job:{
type: Sequelize.INTEGER
}
});
**// in routes at job.js file**
const express = require('express');
const router = express.Router();
const Job = require('../models/Job')
//test
router.get('/test',(req, res)=>{
res.send("As rotas estão funcionando");
})
//add
router.post("/add", (req, res)=>{
let {title, salary, company, description, email, new_job} = req.body;
//insert
Job.create({
title,
salary,
company,
description,
email,
new_job
})
.then(()=>{
res.redirect('/');
})
.catch(err =>{
console.log(err);
});
});
module.exports = router;
Upvotes: 0
Views: 19
Reputation: 1
I solved it, I had forgotten to give module.exports = Job ;-;
Upvotes: 0