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

Classroom count route

parent a3c91fbb
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!38Classroom count route
const express = require('express');
const classroomApp = express.Router();
const libs = `${process.cwd()}/libs`;
const squel = require('squel');
const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
let rqf = new ReqQueryFields();
rqf.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'
}
});
classroomApp.get('/count', rqf.parse(), rqf.build(), (req, res, next) => {
console.log(req.filter);
req.sql.from('escola')
.field('SUM(escola.num_salas)', '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.local_func_predio_escolar = 1');
next();
}, query, response('classroom'));
module.exports = classroomApp;
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