feat: Cities uses GenericHandler

This commit is contained in:
2023-10-09 12:39:39 -06:00
parent 54387add66
commit d01f62004f
18 changed files with 124 additions and 59 deletions

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getCitiesList);
router.get('/find', services.findCitiesList);
router.get('/:id', services.getCity);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -1,28 +1,33 @@
"use strict";
const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const { GenericHandler } = require( `${ROOT_PATH}/${HANDLERS_PATH}/Generic.handler.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/cities.model.js` );
const getCitiesList = async(req, res) => {
const generic = new GenericHandler( Model, "city_name" );
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
const retVal = await generic.getList(page , elements);
res.send( retVal );
};
const findCitiesList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
filter = { "city_name" : { $regex: re, $options: 'i' }};
const findList = async(req, res) => {
const findString = req.query.regex || null;
const { page , elements } = getPagination( req.query );
let retVal;
if( findString ){
retVal = await generic.findList( findString, page, elements );
}else{
retVal = await generic.getList(page , elements);
}
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page, elements, Model, filter );
res.send( retVal );
};
const getCity = async(req, res) => {
const retVal = await Model.findById( req.params.id );
const getById = async(req, res) => {
const id=req.params.id;
const retVal = await generic.getById( id );
res.send( retVal );
};
module.exports = { getCitiesList , findCitiesList , getCity };
module.exports = { getList , findList , getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getCountriesList);
router.get('/find', services.findCountriesList);
router.get('/:id', services.getCountry);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/countries.model.js` );
const getCountriesList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findCountriesList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findCountriesList = async(req, res) => {
res.send( retVal );
};
const getCountry = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getCountriesList, findCountriesList, getCountry };
module.exports = { getList, findList, getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getMetaDataList);
router.get('/find', services.findMetaDataList);
router.get('/:id', services.getMetaData);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/meta-data.model.js` );
const getMetaDataList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findMetaDataList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findMetaDataList = async(req, res) => {
res.send( retVal );
};
const getMetaData = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getMetaDataList, findMetaDataList, getMetaData };
module.exports = { getList, findList, getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getMetaGroupsList);
router.get('/find', services.findMetaGroupsList);
router.get('/:id', services.getMetaGroups);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/meta-groups.model.js` );
const getMetaGroupsList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findMetaGroupsList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findMetaGroupsList = async(req, res) => {
res.send( retVal );
};
const getMetaGroups = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getMetaGroupsList, findMetaGroupsList, getMetaGroups };
module.exports = { getList, findList, getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getProductCategoriesList);
router.get('/find', services.findProductCategoriesList);
router.get('/:id', services.getProductCategory );
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/product-categories.model.js` );
const getProductCategoriesList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findProductCategoriesList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findProductCategoriesList = async(req, res) => {
res.send( retVal );
};
const getProductCategory = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getProductCategoriesList, findProductCategoriesList, getProductCategory };
module.exports = { getList, findList, getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getProductsList);
router.get('/find', services.findProductsList);
router.get('/:id', services.getProduct);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/products.model.js` );
const getProductsList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findProductsList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findProductsList = async(req, res) => {
res.send( retVal );
};
const getProduct = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getProductsList, findProductsList, getProduct };
module.exports = { getList, findList, getById };

View File

@@ -2,8 +2,8 @@
const router = require('express').Router();
const services= require('./services.js');
router.get('/', services.getStatesList);
router.get('/find', services.findStatesList);
router.get('/:id', services.getState);
router.get('/', services.getList);
router.get('/find', services.findList);
router.get('/:id', services.getById);
module.exports = router;

View File

@@ -3,13 +3,13 @@ const { ROOT_PATH, LIB_PATH, MODELS_PATH, HANDLERS_PATH } = process.env;
const { getPagination , getPage } = require( `${ROOT_PATH}/${LIB_PATH}/Misc.js` );
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/states.model.js` );
const getStatesList = async(req, res) => {
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await getPage( page , elements, Model );
res.send( retVal );
};
const findStatesList = async(req, res) => {
const findList = async(req, res) => {
let filter=null;
if( req.query.regex ){
const re = new RegExp( req.query.regex );
@@ -20,9 +20,9 @@ const findStatesList = async(req, res) => {
res.send( retVal );
};
const getState = async(req, res) => {
const getById = async(req, res) => {
const retVal = await Model.findById( req.params.id );
res.send( retVal );
};
module.exports = { getStatesList, findStatesList, getState };
module.exports = { getList, findList, getById };