Controllers + Services

  1. 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.

  2. Grab all category services to one object in services/index.js

    See the Pen 26 - Category-services__index.js by Andrii (@imitator) on CodePen.

  3. Refactor controllers due to changes:
    • Remove line: const { Category } = require('../../models'); and import service
    • Use service in every controller in front of model