Files
ETAApi/sections/cities/services.js

34 lines
1.1 KiB
JavaScript

"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 generic = new GenericHandler( Model, "city_name" );
const getList = async(req, res) => {
const { page , elements } = getPagination( req.query );
const retVal = await generic.getList(page , elements);
res.send( retVal );
};
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);
}
res.send( retVal );
};
const getById = async(req, res) => {
const id=req.params.id;
const retVal = await generic.getById( id );
res.send( retVal );
};
module.exports = { getList , findList , getById };