feat: Adding states endpoint and regex find to current endpoints
This commit is contained in:
@@ -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 citiesModel = require( `${ROOT_PATH}/${MODELS_PATH}/cities.model.js` );
|
||||
const Model = require( `${ROOT_PATH}/${MODELS_PATH}/cities.model.js` );
|
||||
|
||||
const getCitiesList = async(req, res) => {
|
||||
const { page , elements } = getPagination( req.query );
|
||||
const retVal = await queryPage( page , elements, citiesModel );
|
||||
const retVal = await queryPage( page , elements, Model );
|
||||
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 { page , elements } = getPagination( req.query );
|
||||
const retVal = await queryPage( page, elements, Model, filter );
|
||||
res.send( retVal );
|
||||
};
|
||||
|
||||
const getCity = async(req, res) => {
|
||||
const retVal = await citiesModel.findById( req.params.id );
|
||||
const retVal = await Model.findById( req.params.id );
|
||||
res.send( retVal );
|
||||
};
|
||||
|
||||
module.exports = { getCitiesList , getCity };
|
||||
module.exports = { getCitiesList , findCitiesList , getCity };
|
||||
|
||||
Reference in New Issue
Block a user