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.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 };