Documente Academic
Documente Profesional
Documente Cultură
Inside this cats.js file inside the model folder is where you create the SCHEMA (or the
blueprint that structures the data for that specific object)
//routes go here
//the route should be just / because in the index theres already an
implied /cats
catRouter.route("/")
.get((req, res) => {
//use .find() to get database document
CatModel.find(req.query,(err, foundCats) =>{
if (err) return res.send(err);
res.status(200).send(foundCats);
})
})
const { id } = req.params;
// find and remove cat matching id:
cats = cats.filter(cat => cat._id !== id);
//send back the message the cat was removed
res.status(204).send();
})
//PUT one
//youll need to include {_id:req.params.id}, set the req.body, then
set a new value on the body with {new:true}
//{new:true} bypasses the default and sends back the updated version
instead of the old version
module.exports = catRouter;