Since REPLACE INTO inserts when the ID passed in does not exist, there's no need to have separate INSERT INTO functions
Every controller-model pair should combine PUT & POST verbs into one function.
Process
Delete INSERT INTO function in each model, renaming REPLACE INTO function
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)
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
Context
REPLACE INTO
inserts when theID
passed in does not exist, there's no need to have separateINSERT INTO
functionsPUT
&POST
verbs into one function.Process
INSERT INTO
function in each model, renamingREPLACE INTO
functionconst { id = null } = req.params
in order to get the id out, giving it a default value ofnull
ifreq.params.id
does not exist (which will happen when someone isPOST
ing)PUT
&POST
routes to newly combined controller functionsTake 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