We want to mirror the same functionality we built for Trees onto Insects. This includes:
id, name, millimeters, sorted by millimeters.id.id.id matches in URL/body.name (using a “like” query) if desired.insects.js in server/routes.GET /insects, GET /insects/:id, POST /insects, DELETE /insects/:id, PUT /insects/:id, optional GET /insects/search/:term.findAll, findByPk, create, destroy, save) as in the Trees routes.File Name & Location: server/routes/insects.js
// Example skeleton (simplified):
// GET /insects
// Insect.findAll({ attributes: ['id','name','millimeters'], order: [['millimeters','ASC']] })
// GET /insects/:id
// Insect.findByPk(id)
// POST /insects
// Insect.create(body)
// DELETE /insects/:id
// Insect.destroy({ where: { id } })
// PUT /insects/:id
// Check param/body match
// Find insect, update fields, save
// (Optional) GET /insects/search/:term (like query by name)
Expected Input: Various HTTP methods with JSON bodies or URL params.
Expected Output: Insect data in JSON or error messages for invalid requests.
trees.js, changing attribute names to match insects’ fields (e.g., name, description, fact, territory, millimeters).millimeters > 0), unique name constraints, etc.Step-by-Step Directions:
insects.js if it doesn’t exist.Insect from the models folder.Explanations & Analogies: The Insects resource is analogous to Trees; the only difference is which fields the database stores. The CRUD logic is effectively the same.
Real World Example: If the system also needs insects data for a nature or scientific study app, having parallel routes is practical.
Confirm your Insects data is accessible and modifiable just like Trees. If your application uses the many-to-many relationships, these endpoints are crucial for referencing insect IDs.