Controllers + Services
-
Create services/category.services.js
See the Pen 25 - Catgegory.services__mongoDb_web-server by Andrii (@imitator) on CodePen.
In this case const { Category } = require('../models'); imported only once.
-
Grab all category services to one object in services/index.js
See the Pen 26 - Category-services__index.js by Andrii (@imitator) on CodePen.
-
Refactor controllers due to changes:
- Remove line: const { Category } = require('../../models'); and import service
- Use service in every controller in front of model
-
POST
-
See the Pen 27 - POST ctrl acc. to services by Andrii (@imitator) on CodePen.
-
-
getAll
-
See the Pen 28 - GET_getAll_ ctrl acc. to services by Andrii (@imitator) on CodePen.
-
-
getItem by id
-
See the Pen 29 - GET__getById__ ctrl acc. to services by Andrii (@imitator) on CodePen.
-
-
UPDATE
-
See the Pen 27 - PUT__ctrl acc. to services by Andrii (@imitator) on CodePen.
-
-
DELETE
-
See the Pen 31 - DELETE__ctrl acc. to services by Andrii (@imitator) on CodePen.
P.S. In DELETE controller remember about second way of response.
-