我正在尝试学习sequelize.js,我得到了更新方法的TypeError:
TypeError:无法读取未定义
的属性'params'我试图获取路线的参数并改变它的值。我试图获取用户名并更改其用户名和密码。这是我的代码:
module.exports = function (sequelize) {
var model = require("../models/employer_model")(sequelize);
var Employer = model.Employer;
return {
create: function (req, res) {
if (req.body.username && req.body.password != null) {
var newEmployer = {
username: req.body.username,
password: req.body.password
}
Employer.create(newEmployer).success(function () {
res.send(200);
res.json(req.dataValues);
});} else {
res.send(406);
}
},
get: function (req, res) {
Employer.findAll().success(function (employers) {
res.send(employers);
});
},
update: function (req, res) {
Employer.req.params.id = req.body;
Employer.save().success(function (employers){
res.send(200);
res.json(req.dataValues);
});
}
};
};
这是server.js
// app dependencies
var express = require("express");
var Sequelize = require("sequelize");
var bodyParser = require('body-parser');
var morgan = require('morgan');
var app = express();
var models = require("./models");
//sequalize initialization
var sequelize = new Sequelize("postgres://rahul:jobletics@localhost:5432/jobletics");
var employerRoute = require("./routes/employer_route")(sequelize);
//middleware
app.use(bodyParser());
app.use(morgan('dev'));
models.sequelize.sync().success(function (err) {
console.log('Express server listening on port 5000');
app.get("/employer", employerRoute.get);
app.post("/employer", employerRoute.create);
app.put("/employer/:id", employerRoute.update);
app.listen(5000);
});
有什么想法吗?
答案 0 :(得分:0)
答案 1 :(得分:0)
Employer.req.params.id = req.body;
我猜这里Employer.req
未定义