Last active
March 8, 2021 14:57
-
-
Save gorkamu/58871619f7237abb87be797c6d703943 to your computer and use it in GitHub Desktop.
Ejemplo de método DELETE en una API REST con Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function deleteAlbum(req, res){ | |
var albumId = req.params.id; | |
Album.findById(albumId, function(err, album){ | |
if(err){ | |
res.status(500).send({message: 'Error 500 al devolver el album'}); | |
}else{ | |
if(album){ | |
album.remove(err => { | |
if(err){ | |
res.status(500).send({message: 'Error 500 al borrar el album'}); | |
}else{ | |
res.status(200).send({message:'El album se ha borrado'}); | |
} | |
}); | |
}else{ | |
res.status(400).send({message:'No hay album'}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment