Skip to content
Snippets Groups Projects
Commit 40db46fd authored by Gabriel Ruschel's avatar Gabriel Ruschel
Browse files

Fix filters

parent 9b31c6d1
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!65Fix filters
Pipeline #
...@@ -90,12 +90,12 @@ rqf.addField({ ...@@ -90,12 +90,12 @@ rqf.addField({
relation: '=', relation: '=',
type: 'integer', type: 'integer',
field: 'estado_id', field: 'estado_id',
table: 'adh_idh_uf' table: '@'
}, },
join: { join: {
primary: 'id', primary: 'id',
foreign: 'estado_id', foreign: 'estado_id',
foreignTable: 'adh_idh_uf' foreignTable: '@'
} }
}); });
...@@ -107,22 +107,24 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => { ...@@ -107,22 +107,24 @@ idhmeApp.get('/', rqf.parse(), (req, res, next) => {
message: 'Wrong/No filter specified' message: 'Wrong/No filter specified'
}); });
} }
if ("state" in req.filter) {
// console.log("sim"); if (!("state" in req.filter) && !("city" in req.filter)) {
req.sql.from('adh_idh_uf') next({
.field('adh_idh_uf.idhm_e', 'total') status: 400,
.field('adh_idh_uf.ano_censo', 'year') message: 'Wrong/No filter specified'
.field('adh_idh_uf.estado_id', 'state_id'); });
} else if ("city" in req.filter) { }
if ("city" in req.filter) {
req.sql.from('adh_idh') req.sql.from('adh_idh')
.field('adh_idh.idhm_e', 'total') .field('adh_idh.idhm_e', 'total')
.field('adh_idh.ano_censo', 'year') .field('adh_idh.ano_censo', 'year')
.field('adh_idh.municipio_id', 'city_id'); .field('adh_idh.municipio_id', 'city_id');
} else { } else {
next({ // console.log("sim");
status: 400, req.sql.from('adh_idh_uf')
message: 'Wrong/No filter specified' .field('adh_idh_uf.idhm_e', 'total')
}); .field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id');
} }
next(); next();
}, rqf.build(), query, response('idhme')); }, rqf.build(), query, response('idhme'));
......
...@@ -90,12 +90,12 @@ rqf.addField({ ...@@ -90,12 +90,12 @@ rqf.addField({
relation: '=', relation: '=',
type: 'integer', type: 'integer',
field: 'estado_id', field: 'estado_id',
table: 'adh_idh_uf' table: '@'
}, },
join: { join: {
primary: 'id', primary: 'id',
foreign: 'estado_id', foreign: 'estado_id',
foreignTable: 'adh_idh_uf' foreignTable: '@'
} }
}); });
...@@ -107,21 +107,23 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => { ...@@ -107,21 +107,23 @@ idhmlApp.get('/', rqf.parse(), (req, res, next) => {
message: 'Wrong/No filter specified' message: 'Wrong/No filter specified'
}); });
} }
if ("state" in req.filter) { if (!("state" in req.filter) && !("city" in req.filter)) {
req.sql.from('adh_idh_uf') next({
.field('adh_idh_uf.idhm_l', 'total') status: 400,
.field('adh_idh_uf.ano_censo', 'year') message: 'Wrong/No filter specified'
.field('adh_idh_uf.estado_id', 'state_id'); });
} else if ("city" in req.filter) { }
if ("city" in req.filter) {
req.sql.from('adh_idh') req.sql.from('adh_idh')
.field('adh_idh.idhm_l', 'total') .field('adh_idh.idhm_l', 'total')
.field('adh_idh.ano_censo', 'year') .field('adh_idh.ano_censo', 'year')
.field('adh_idh.municipio_id', 'city_id'); .field('adh_idh.municipio_id', 'city_id');
} else { } else {
next({ // console.log("sim");
status: 400, req.sql.from('adh_idh_uf')
message: 'Wrong/No filter specified' .field('adh_idh_uf.idhm_l', 'total')
}); .field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id');
} }
next(); next();
}, rqf.build(), query, response('idhml')); }, rqf.build(), query, response('idhml'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment