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

Count schools by state, region, city and other filters

parent 124f7fce
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!47School number count
Pipeline #
......@@ -13,6 +13,7 @@ const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
let rqf = new ReqQueryFields();
let rqfCount = new ReqQueryFields();
rqf.addField({
name: 'filter',
......@@ -72,6 +73,124 @@ rqf.addField({
}
});
rqfCount.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'id',
table: 'escola',
tableField: 'id',
where: {
relation: '=',
type: 'integer',
field: 'id'
}
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'municipio_id',
table: 'escola'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'escola'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: 'nome',
resultField: 'region_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'escola'
}
}).addValue({
name: 'year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '=',
type: 'integer',
field: 'ano_censo',
table: 'escola'
}
}).addValue({
name: 'adm_dependency',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_id',
foreignTable: 'escola'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_detailed_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_priv',
foreignTable: 'escola'
}
// tem problemas
}).addValue({
name: 'government_agreement',
table: 'escola',
tableField: 'conveniada_pp',
resultField: 'conveniada_poder_publico',
where: {
relation: '=',
type: 'integer',
field: 'conveniada_pp'
}
});
schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
console.log(req.filter);
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) {
......@@ -90,4 +209,16 @@ schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
next();
}, query, response('school'));
schoolApp.get('/count', rqfCount.parse(), rqfCount.build(), (req, res, next) => {
req.sql.from('escola')
.field('COUNT(escola.id)', 'total')
.field("'Brasil'", 'name')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1');
next();
}, query, response('school'));
module.exports = schoolApp;
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