chicken-sloths / bangazon-api-sprint1

API for a mock Amazon + Etsy platform providing developers access to the company's employee & product data
0 stars 0 forks source link

Combine db INSERT INTO with REPLACE INTO #103

Closed DavidLarsKetch closed 6 years ago

DavidLarsKetch commented 6 years ago

Context

  1. Since REPLACE INTO inserts when the ID passed in does not exist, there's no need to have separate INSERT INTO functions
  2. Every controller-model pair should combine PUT & POST verbs into one function.

Process

  1. Delete INSERT INTO function in each model, renaming REPLACE INTO function
  2. Do something like this: const { id = null } = req.params in order to get the id out, giving it a default value of null if req.params.id does not exist (which will happen when someone is POSTing)
  3. Hook up PUT & POST routes to newly combined controller functions
    • [x] computers
    • [x] customers
    • [x] payment options
    • [x] training programs
    • [x] employees
    • [x] products
    • [x] orders
    • [x] departments
    • [x] product types

Take a look at routes/products/productTypes.js, controllers/products/productTypesCtrl.js & models/products/ProductTypesModel.js

Expected Result

PUT & POST should continue to work as expected