0
Restify을 SQLite3 데이터베이스와 함께 사용하고 있습니다.Put Restrict + SQLite3의 특정 필드 만 업데이트
위해server.put('/users/:userid', function(req, res, next) {
bcrypt.hash(req.body.password, 10, function(err, hash) {
if (err) {
res.send(err);
} else {
db.run('UPDATE users SET username = ?, first_name = ?, last_name = ?, email = ?, password = ? WHERE id = ?', req.body.username, req.body.first_name, req.body.last_name, req.body.email, hash, req.params.userid, function(err) {
if (err) {
res.send(err);
} else {
res.json({ message:'Successfully updated user'});
}
});
}
});
next();
});
이 모든 다시 속성에 하나의 통과해야 작동하려면 : 오직 이메일 경우
{
"username": "greg",
"first_name": "Greg",
"last_name": "Davis",
"email": "[email protected]",
"password": "password"
}
은 분명히이 중복되어 지금까지 내가 내 put
방법에 대해 무엇을 가지고 변경해야합니다. 다음과 같이 전달하면 충분할 수 있도록 코드를 어떻게 수정할 수 있습니까?
{
"email": "[email protected]",
}
내가 좋아 새로운 암호가 지정되어있는 경우가 더 복잡로, 확인하려면 몇 가지 추가 로직을 추가하지만, 모든 단일 필드에 대해 논리에 추가하고 과도한 것 같다.