feat: Adding product-categories endpoint

This commit is contained in:
2023-10-05 23:39:21 -06:00
parent 857a8bf18b
commit bf65d9a5cf
4 changed files with 33 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
'use strict';
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getProductCategoriesList);
router.get('/:id', services.getProductCategory );
module.exports = router;

View File

@@ -0,0 +1,17 @@
"use strict";
const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , queryPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const productCategoriesModel = require( `${ROOT_PATH}/${MODELS_PATH}/product-categories.model.js` );
const getProductCategoriesList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await queryPage( page , elements, productCategoriesModel );
res.send( retVal );
};
const getProductCategory = async(req, res) => {
const retVal = await productCategoriesModel.findById( req.params.id );
res.send( retVal );
};
module.exports = { getProductCategoriesList , getProductCategory };