feat: Adding states endpoint and regex find to current endpoints

This commit is contained in:
2023-10-06 00:23:36 -06:00
parent bf65d9a5cf
commit ce3ec074eb
11 changed files with 117 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getProductCategoriesList);
router.get('/find', services.findProductCategoriesList);
router.get('/:id', services.getProductCategory );
module.exports = router;

View File

@@ -1,17 +1,28 @@
"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 Model = 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 );
const retVal = await queryPage( page , elements, Model );
res.send( retVal );
};
const findProductCategoriesList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
filter = { "name" : { $regex: re, $options: 'i' }};
}
const { page , elements } = getPagination( req.query );
const retVal = await queryPage( page, elements, Model, filter );
res.send( retVal );
};
const getProductCategory = async(req, res) => {
const retVal = await productCategoriesModel.findById( req.params.id );
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getProductCategoriesList , getProductCategory };
module.exports = { getProductCategoriesList, findProductCategoriesList, getProductCategory };