Skip to content
Snippets Groups Projects
Commit 58386b3a authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'idh_r' into 'development'

Fix dims in IDHM and IDHMR

See merge request !68
parents 809cb5db c174f21d
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!68Fix dims in IDHM and IDHMR
Pipeline #
module.exports = function stateName(id) {
switch (id) {
case 11:
return 'Rondônia';
case 12:
return 'Acre';
case 13:
return 'Amazonas';
case 14:
return 'Roraima';
case 15:
return 'Pará';
case 16:
return 'Amapá';
case 17:
return 'Tocantins';
case 21:
return 'Maranhão';
case 22:
return'Piauí';
case 23:
return 'Ceará';
case 24:
return 'Rio Grande do Norte';
case 25:
return 'Paraíba';
case 26:
return 'Pernambuco';
case 27:
return 'Alagoas';
case 28:
return 'Sergipe';
case 29:
return 'Bahia';
case 31:
return 'Minas Gerais';
case 32:
return 'Espírito Santo';
case 33:
return 'Rio de Janeiro ';
case 35:
return 'São Paulo';
case 41:
return 'Paraná';
case 42:
return 'Santa Catarina';
case 43:
return 'Rio Grande do Sul';
case 50:
return 'Mato Grosso do Sul';
case 51:
return 'Mato Grosso';
case 52:
return 'Goiás';
case 53:
return 'Distrito Federal';
}
};
...@@ -16,6 +16,7 @@ const educationType = require(`${libs}/convert/educationType`); ...@@ -16,6 +16,7 @@ const educationType = require(`${libs}/convert/educationType`);
const citySize = require(`${libs}/convert/citySize`); const citySize = require(`${libs}/convert/citySize`);
const incomeLevel = require(`${libs}/convert/incomeLevel`); const incomeLevel = require(`${libs}/convert/incomeLevel`);
const idhmLevel = require(`${libs}/convert/idhmLevel`); const idhmLevel = require(`${libs}/convert/idhmLevel`);
const stateName = require(`${libs}/convert/stateName`);
const ids = { const ids = {
gender_id: gender, gender_id: gender,
...@@ -63,7 +64,8 @@ const ids = { ...@@ -63,7 +64,8 @@ const ids = {
education_type_id: educationType, education_type_id: educationType,
income_level_id: incomeLevel, income_level_id: incomeLevel,
city_size_id: citySize, city_size_id: citySize,
idhm_level_id: idhmLevel idhm_level_id: idhmLevel,
state_id: stateName
}; };
function transform(removeId=false) { function transform(removeId=false) {
......
...@@ -150,13 +150,6 @@ rqf.addField({ ...@@ -150,13 +150,6 @@ rqf.addField({
idhmApp.get('/', rqf.parse(), (req, res, next) => { idhmApp.get('/', rqf.parse(), (req, res, next) => {
log.debug(req.sql.toParam()); log.debug(req.sql.toParam());
if((Object.keys(req.filter).length === 0) && (Object.keys(req.dims).length === 0)) { if((Object.keys(req.filter).length === 0) && (Object.keys(req.dims).length === 0)) {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
if ("state" in req.filter && !("city" in req.filter)) {
req.sql.from('adh_idh_uf') req.sql.from('adh_idh_uf')
.field('adh_idh_uf.idhm', 'total') .field('adh_idh_uf.idhm', 'total')
.field('adh_idh_uf.ano_censo', 'year') .field('adh_idh_uf.ano_censo', 'year')
...@@ -164,21 +157,32 @@ idhmApp.get('/', rqf.parse(), (req, res, next) => { ...@@ -164,21 +157,32 @@ idhmApp.get('/', rqf.parse(), (req, res, next) => {
.group('adh_idh_uf.idhm') .group('adh_idh_uf.idhm')
.group('adh_idh_uf.ano_censo') .group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id') .group('adh_idh_uf.estado_id')
} else if ("city" in req.filter) { } else if ("state" in req.filter && !("city" in req.filter) && !("city" in req.dims)) {
req.sql.from('adh_idh_uf')
.field('adh_idh_uf.idhm', 'total')
.field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id')
.group('adh_idh_uf.idhm')
.group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id')
} else if ("city" in req.filter || "city" in req.dims) {
req.sql.from('adh_idh') req.sql.from('adh_idh')
.field('adh_idh.idhm', 'total') .field('adh_idh.idhm', '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')
.field('adh_idh.estado_id', 'city_id') .field('adh_idh.estado_id', 'state_id')
.group('adh_idh.idhm') .group('adh_idh.idhm')
.group('adh_idh.ano_censo') .group('adh_idh.ano_censo')
.group('adh_idh.municipio_id') .group('adh_idh.municipio_id')
.group('adh_idh.estado_id') .group('adh_idh.estado_id')
} else { } else {
next({ req.sql.from('adh_idh_uf')
status: 400, .field('adh_idh_uf.idhm', 'total')
message: 'Wrong/No filter specified' .field('adh_idh_uf.ano_censo', 'year')
}); .field('adh_idh_uf.estado_id', 'state_id')
.group('adh_idh_uf.idhm')
.group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id')
} }
next(); next();
}, rqf.build(), query, id2str.transform(), response('idhm')); }, rqf.build(), query, id2str.transform(), response('idhm'));
......
...@@ -126,31 +126,42 @@ rqf.addField({ ...@@ -126,31 +126,42 @@ rqf.addField({
idhmrApp.get('/', rqf.parse(), (req, res, next) => { idhmrApp.get('/', rqf.parse(), (req, res, next) => {
log.debug(req.sql.toParam()); log.debug(req.sql.toParam());
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0 ) { if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0 ) {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
if ("state" in req.filter && !("city" in req.filter)) {
req.sql.from('adh_idh_uf') req.sql.from('adh_idh_uf')
.field('adh_idh_uf.idhm_r', 'total') .field('adh_idh_uf.idhm_r', 'total')
.field('adh_idh_uf.ano_censo', 'year') .field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id'); .field('adh_idh_uf.estado_id', 'state_id')
} else if ("city" in req.filter) { .group('adh_idh_uf.idhm_r')
.group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id')
} else if ("state" in req.filter && !("city" in req.filter) && !("city" in req.dims)) {
req.sql.from('adh_idh_uf')
.field('adh_idh_uf.idhm_r', 'total')
.field('adh_idh_uf.ano_censo', 'year')
.field('adh_idh_uf.estado_id', 'state_id')
.group('adh_idh_uf.idhm_r')
.group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id')
} else if ("city" in req.filter || "city" in req.dims) {
req.sql.from('adh_idh') req.sql.from('adh_idh')
.field('adh_idh.idhm_r', 'total') .field('adh_idh.idhm_r', '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')
.field('adh_idh.estado_id', 'estado_id'); .field('adh_idh.estado_id', 'state_id')
.group('adh_idh.idhm_r')
.group('adh_idh.ano_censo')
.group('adh_idh.municipio_id')
.group('adh_idh.estado_id')
} else { } else {
next({ req.sql.from('adh_idh_uf')
status: 400, .field('adh_idh_uf.idhm_r', 'total')
message: 'Wrong/No filter specified' .field('adh_idh_uf.ano_censo', 'year')
}); .field('adh_idh_uf.estado_id', 'state_id')
.group('adh_idh_uf.idhm_r')
.group('adh_idh_uf.ano_censo')
.group('adh_idh_uf.estado_id')
} }
next(); next();
}, rqf.build(),query, response('idhmr')); }, rqf.build(),query, id2str.transform(), response('idhmr'));
module.exports = idhmrApp; module.exports = idhmrApp;
...@@ -49,30 +49,43 @@ describe('request idhm', () => { ...@@ -49,30 +49,43 @@ describe('request idhm', () => {
res.body.result[0].should.have.property('total'); res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year'); res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('state_id'); res.body.result[0].should.have.property('state_id');
res.body.result[0].should.have.property('state_name');
done(); done();
}); });
}); });
it('should list idhm with invalid filters', (done) => { it('should list idhm with valid dims', (done) => {
chai.request(server) chai.request(server)
.get('/api/v1/idhm?filter=foo:2010,bar:41') .get('/api/v1/idhm?dims=city')
.end((err, res) => { .end((err, res) => {
res.should.have.status(400); res.should.have.status(200);
res.should.be.json; res.should.be.json;
res.body.should.have.property('error'); res.body.should.have.property('result');
res.body.error.should.be.equal('Wrong/No filter specified'); res.body.result.should.be.a('array');
res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('city_id');
res.body.result[0].should.have.property('state_id');
res.body.result[0].should.have.property('city_name');
res.body.result[0].should.have.property('state_name');
done(); done();
}); });
}); });
it('should return 400 with no filters', (done) => { it('should list idhm with valid filtes and dims', (done) => {
chai.request(server) chai.request(server)
.get('/api/v1/idhm') .get('/api/v1/idhm?filter=state:41&dims=idhm_level')
.end((err, res) => { .end((err, res) => {
res.should.have.status(400); res.should.have.status(200);
res.should.be.json; res.should.be.json;
res.body.should.have.property('error'); res.body.should.have.property('result');
res.body.error.should.be.equal('Wrong/No filter specified'); res.body.result.should.be.a('array');
res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('state_id');
res.body.result[0].should.have.property('idhm_level_id');
res.body.result[0].should.have.property('state_name');
res.body.result[0].should.have.property('idhm_level_name');
done(); done();
}) })
}); });
......
...@@ -24,57 +24,68 @@ const server = require(`${libs}/app`); ...@@ -24,57 +24,68 @@ const server = require(`${libs}/app`);
chai.use(chaiHttp); chai.use(chaiHttp);
describe('request idhmr', () => { describe('request idhmr', () => {
it('should list the year range', (done) => { it('should list the year range', (done) => {
chai.request(server) chai.request(server)
.get('/api/v1/idhmr/year_range') .get('/api/v1/idhmr/year_range')
.end((err, res) => { .end((err, res) => {
res.should.have.status(200); res.should.have.status(200);
res.should.be.json; res.should.be.json;
res.body.should.have.property('result'); res.body.should.have.property('result');
res.body.result.should.be.a('array'); res.body.result.should.be.a('array');
res.body.result[0].should.have.property('start_year'); res.body.result[0].should.have.property('start_year');
res.body.result[0].should.have.property('end_year'); res.body.result[0].should.have.property('end_year');
done(); done();
}); });
}); });
it('should list idhmr with valid filters', (done) => { it('should list idhmr with valid filters', (done) => {
chai.request(server) chai.request(server)
.get('/api/v1/idhmr?filter=min_year:2000,state:41') .get('/api/v1/idhmr?filter=min_year:2000,state:41')
.end((err, res) => { .end((err, res) => {
res.should.have.status(200); res.should.have.status(200);
res.should.be.json; res.should.be.json;
res.body.should.have.property('result'); res.body.should.have.property('result');
res.body.result.should.be.a('array'); res.body.result.should.be.a('array');
res.body.result[0].should.have.property('total'); res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year'); res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('state_id'); res.body.result[0].should.have.property('state_id');
done(); res.body.result[0].should.have.property('state_name');
}); done();
}); });
});
it('should list idhmr with invalid filters', (done) => {
chai.request(server) it('should list idhmr with valid dims', (done) => {
.get('/api/v1/idhmr?filter=foo:2010,bar:41') chai.request(server)
.end((err, res) => { .get('/api/v1/idhmr?dims=state')
res.should.have.status(400); .end((err, res) => {
res.should.be.json; res.should.have.status(200);
res.body.should.have.property('error'); res.should.be.json;
res.body.error.should.be.equal('Wrong/No filter specified'); res.body.should.have.property('result');
done(); res.body.result.should.be.a('array');
}); res.body.result[0].should.have.property('total');
}); res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('state_id');
it('should return 400 with no filters', (done) => { res.body.result[0].should.have.property('state_name');
chai.request(server) done();
.get('/api/v1/idhmr') });
.end((err, res) => { });
res.should.have.status(400);
res.should.be.json; it('should list idhmr with valid filtes and dims', (done) => {
res.body.should.have.property('error'); chai.request(server)
res.body.error.should.be.equal('Wrong/No filter specified'); .get('/api/v1/idhm?filter=state:41&dims=city')
done(); .end((err, res) => {
}) res.should.have.status(200);
}); res.should.be.json;
res.body.should.have.property('result');
res.body.result.should.be.a('array');
res.body.result[0].should.have.property('total');
res.body.result[0].should.have.property('year');
res.body.result[0].should.have.property('city_id');
res.body.result[0].should.have.property('state_id');
res.body.result[0].should.have.property('city_name');
res.body.result[0].should.have.property('state_name');
done();
})
});
}); });
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