すべてのbodyパラメータがオプションであるREST APIにパッチエンドポイントがあります。手動で各パラメータをチェックせずに実装する最良の方法は何ですか? helpers名前空間のpg-promiseの動的名前付きパラメータ
db.none("update tasks set title=$1, description=$2, value=$3 where id=$4",
[req.body.title, req.body.description, parseInt(req.body.value), req.params.id])
.then(function() {
res.status(200)
.json({
status: "success",
message: "Updated task"
});
})
.catch(function (err) {
return next(err);
});
クエリには4つのパラメータが含まれ、3つの値しか渡されません。これは正しく見えません。最初にあなたの例を修正する必要があります。 –