From 33c25bee7ebedb06ba281f8fe8b45e956a4e10fa Mon Sep 17 00:00:00 2001 From: Pietro Polinari Cavassin <ppc19@inf.ufpr.br> Date: Fri, 12 Aug 2022 11:45:50 -0300 Subject: [PATCH] add mesoregion and microregion filters --- src/libs/routes/city.js | 22 ---------------------- src/libs/routes/mesoregion.js | 12 +++++++++++- src/libs/routes/microregion.js | 21 ++++++++++++++++++++- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/libs/routes/city.js b/src/libs/routes/city.js index 2ebc44d2..1686c850 100644 --- a/src/libs/routes/city.js +++ b/src/libs/routes/city.js @@ -115,27 +115,5 @@ cityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { next(); }, query, response('city')); -cityApp.get('/microregion', rqf.parse(), rqf.build(), (req, res, next) => { - req.sql.from('municipio') - .field('municipio.estado_id', 'state_id') - .field('municipio.microrregiao_id', 'microregion_id') - .field('municipio.nome_microrregiao', 'microregion_name') - .group('municipio.estado_id') - .group('municipio.microrregiao_id') - .group('municipio.nome_microrregiao') - next(); -}, query, response('city/microregion')); - -cityApp.get('/mesoregion', rqf.parse(), rqf.build(), (req, res, next) => { - req.sql.from('municipio') - .field('municipio.estado_id', 'state_id') - .field('municipio.mesorregiao_id', 'mesoregion_id') - .field('municipio.nome_mesorregiao', 'mesoregion_name') - .group('municipio.nome_mesorregiao') - .group('municipio.mesorregiao_id') - .group('municipio.estado_id') - next(); -}, query, response('city/mesoregion')); - module.exports = cityApp; diff --git a/src/libs/routes/mesoregion.js b/src/libs/routes/mesoregion.js index 0feb7627..001976f2 100644 --- a/src/libs/routes/mesoregion.js +++ b/src/libs/routes/mesoregion.js @@ -60,6 +60,15 @@ rqf.addField({ foreign: 'estado_id', foreignTable: 'municipio' } +}).addValue({ + name: 'mesoregion', + table: 'municipio', + tableField: 'mesorregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id' + } }); mesoregionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { @@ -69,7 +78,8 @@ mesoregionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field('municipio.estado_id', 'state_id') .group('municipio.nome_mesorregiao') .group('municipio.mesorregiao_id') - .group('municipio.estado_id'); + .group('municipio.estado_id') + .order('municipio.mesorregiao_id'); next(); }, query, response('mesoregion')); diff --git a/src/libs/routes/microregion.js b/src/libs/routes/microregion.js index 0b9b0e1a..c4aba0fe 100644 --- a/src/libs/routes/microregion.js +++ b/src/libs/routes/microregion.js @@ -60,6 +60,24 @@ rqf.addField({ foreign: 'estado_id', foreignTable: 'municipio' } +}).addValue({ + name: 'mesoregion', + table: 'municipio', + tableField: 'mesorregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id' + } +}).addValue({ + name: 'microregion', + table: 'municipio', + tableField: 'microrregiao_id', + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id' + } }); microregionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { @@ -73,7 +91,8 @@ microregionApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .group('municipio.microrregiao_id') .group('municipio.nome_mesorregiao') .group('municipio.mesorregiao_id') - .group('municipio.estado_id'); + .group('municipio.estado_id') + .order('municipio.microrregiao_id'); next(); }, query, response('microregion')); -- GitLab