我正在尝试从json接收一些数据,我正在使用sequelize来存储我的数据,问题是当我发送帖子请求控制台向我发送错误时:
Error: Invalid value { username: 'phernandez' }
at Object.escape (C:\Users\pablo\Desktop\buildingapp\backend\node_modules\sequelize\lib\sql-string.js:65:11)
at PostgresQueryGenerator.escape (C:\Users\pablo\Desktop\buildingapp\backend\node_modules\sequelize\lib\dialects\abstract\query-generator.js:963:22)
at PostgresQueryGenerator._whereParseSingleValueObject (C:\Users\pablo\Desktop\buildingapp\backend\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2420:41)
我已经更改了邮递员发送中不同参数的类型,因为_I认为我发送的邮寄请求不正确,由邮递员发送x-form-www-urlencoded,然后再次发送正文
//this is the file app.js
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
//and the routes
router.post('/',(req,res)=> {
var usuario=req.body;
console.log(usuario);
Usuario.findOne({
where: {username:usuario},
attributes:['username','password','niv_adm']
})
.then(usuario => {
console.log(usuario);
res.sendStatus(200);
})
.catch(err => console.log(err))
});
我的期望是得到这个好,然后在我正在使用的数据库中进行咨询并返回我需要的数据
答案 0 :(得分:0)
这仍然可以简化(因为使用两种语言不会使任何事情变得容易):
router.post('/',(req,res)=> {
Usuario.findOne({
where: {username: req.body.username},
attributes:['username','password','niv_adm']
})
.then(user => {
console.log(user);
res.sendStatus(200);
})
.catch(err => console.log(err))
});
答案 1 :(得分:0)
我已经解决了这个问题,我只需要在模型部分传递您正在使用的模型的参数,就像这样,非常感谢您
<h1>Hello</h1>
<form>
<section>
<h3 class="header">Login information</h3>
<div id="personal">
<input type="text" id="email" placeholder="Email - first.last@email.com">
<br><br>
<input type="password" id="firstpass" placeholder="Password">
</div>
</section>
<section>
<h3 class="header">One</h3>
<div id="BlockOne">
<input type="password" id="secpass" placeholder="Second Password">
<ul id="environs">
<li><input type="checkbox" name="env" id="env1" value="env1"><label for="env1">env1</label></li>
<li><input type="checkbox" name="env" id="env2" value="env2"><label for="env2">env2</label></li>
<li><input type="checkbox" name="env" id="env3" value="env3"><label for="env3">env3</label></li>
</ul>
</div>
</section>
<section>
<h3 class="header">Two</h3>
<div id="BlockTwo">
<p>Lorem ipsum</p>
</div>
</section>
<br><br>
<input type="submit" value="Run">
</form>