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

Cleaning up model-controller pairs #116

Closed DavidLarsKetch closed 6 years ago

DavidLarsKetch commented 6 years ago

Context

  1. Our models & controllers define methods that call only one function
  2. With ES6, we can (though don't have to) get rid of return statements & { }
  3. Our models generally (though not always) reject(err) and resolve(data). Instead of if... then statements, we can use ternary operators
  4. For example, look at productTypesModel.js & productTypesCtrl which follows these thoughts
  5. Destructuring:
    1. Sometimes we are destructuring req in the controller and passing each variable into the model, other times, we are passing in req and destructuring in the model
    2. This should be uniform

Process

  1. Go thru every controller-model pair
  2. Remove return & { } where possible
  3. Change if...then statements in models to ternary operators where possible
  4. Not every function can have its { } or return removed or use a ternary operator, and that's okay!
  5. In controllers, pass in req.body & req.params.id (where appropriate) and destructure in the appropriate model, not in the controller

Expected Result

ES6-ified!