Update DELETE to return 404 if resource doesn't exist

This commit is contained in:
Typicode
2015-10-13 21:55:14 +02:00
parent 4be2f30fdb
commit 94cfbabd41
2 changed files with 13 additions and 2 deletions

View File

@ -230,7 +230,7 @@ module.exports = function (db, name) {
// DELETE /name/:id
function destroy (req, res, next) {
db(name).removeById(utils.toNative(req.params.id))
var resource = db(name).removeById(utils.toNative(req.params.id))
// Remove dependents documents
var removable = db._.getRemovable(db.object)
@ -239,7 +239,10 @@ module.exports = function (db, name) {
db(item.name).removeById(item.id)
})
res.locals.data = {}
if (resource) {
res.locals.data = {}
}
next()
}