We want to remove a tree record from the database when given an id. If the id does not exist, we should handle that gracefully.
id from req.params.Tree.destroy with a where condition matching the id.File Name & Location: server/routes/trees.js
// DELETE /trees/:id pseudocode:
// 1. Read id from req.params.id
// 2. const deleted = await Tree.destroy({ where: { id } })
// 3. if (deleted === 0) { return error response }
// 4. otherwise, return success JSON
Expected Input: A DELETE request to /trees/:id.
Expected Output: A JSON success message or a “not found” error JSON.
Tree.destroy call with minimal logic for the “not found” scenario.ids are provided.Step-by-Step Directions:
trees.js and find or create the DELETE route.id from req.params.Tree.destroy passing in a where object.Explanations & Analogies: Deleting a record is like permanently removing a book card from the library system. If the book card doesn’t exist, you can’t remove it.
Real World Example: Removing a no-longer-valid record from an inventory or user database.
Confirm the record is indeed removed. Try deleting the same id again to ensure your “Tree not found” logic is triggered.