Our models & controllers define methods that call only one function
With ES6, we can (though don't have to) get rid of return statements & { }
Our modelsgenerally (though not always) reject(err) and resolve(data). Instead of if... then statements, we can use ternary operators
For example, look at productTypesModel.js & productTypesCtrl which follows these thoughts
Destructuring:
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
This should be uniform
Process
Go thru every controller-model pair
Remove return & { } where possible
Change if...then statements in models to ternary operators where possible
Not every function can have its { } or return removed or use a ternary operator, and that's okay!
In controllers, pass in req.body & req.params.id (where appropriate) and destructure in the appropriate model, not in the controller
Context
models
&controllers
define methods that call only one functionreturn
statements &{ }
models
generally (though not always)reject(err)
andresolve(data)
. Instead ofif... then
statements, we can use ternary operatorsproductTypesModel.js
&productTypesCtrl
which follows these thoughtsreq
in thecontroller
and passing each variable into themodel
, other times, we are passing inreq
and destructuring in themodel
Process
controller-model
pairreturn
&{ }
where possibleif...then
statements inmodels
to ternary operators where possible{ }
orreturn
removed or use a ternary operator, and that's okay!controllers
, pass inreq.body
&req.params.id
(where appropriate) and destructure in the appropriatemodel
, not in thecontroller
Expected Result
ES6-ified!