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

Merge branch 'portalMecSchool' into development

parents 36ef8556 74670a3c
No related branches found
No related tags found
1 merge request!155Release v1.7.0
......@@ -240,13 +240,17 @@ class ReqQueryFields {
if (Array.isArray(value.resultField)) {
value.tableField.forEach((f, i) => {
sql.field(table+'.'+f, value.resultField[i] || f)
.group(table+'.'+f)
if(!value.dontGroup) {
sql.group(table+'.'+f)
.order(table+'.'+f);
}
})
}else{
sql.field(table+'.'+value.tableField, value.resultField || value.tableField)
.order(table+'.'+value.tableField)
if(!value.dontGroup) {
sql.order(table+'.'+value.tableField)
.group(table+'.'+value.tableField);
}
}
}
// Se o valor é um campo para ser usado no WHERE
......
......@@ -78,8 +78,6 @@ const cub = require(`${libs}/routes/cub`);
const classCount = require(`${libs}/routes/classCount`);
const portalMecSchoolName = require(`${libs}/routes/portalMecSchoolName`);
const portalMecInep = require(`${libs}/routes/portalMecInep`);
api.get('/', (req, res) => {
......@@ -123,7 +121,6 @@ api.use('/cub', cub);
api.use('/auxiliar', auxiliar);
api.use('/verify_teacher', verifyTeacher);
api.use('/class_count', classCount);
api.use('/portal_mec_school_name', portalMecSchoolName);
api.use('/poltal_mec_inep', portalMecInep);
module.exports = api;
const express = require('express');
const portalMecSchoolName = express.Router();
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const squel = require('squel');
const query = require(`${libs}/middlewares/query`).query;
const response = require(`${libs}/middlewares/response`);
const id2str = require(`${libs}/middlewares/id2str`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
const request = require(`request`);
const config = require(`${libs}/config`);
const passport = require('passport');
const download = require(`${libs}/middlewares/downloadDatabase`);
const addMissing = require(`${libs}/middlewares/addMissing`);
const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware;
let rqf = new ReqQueryFields();
// Return location
portalMecSchoolName.get('/year_range', cache('15 day'), (req, res, next) => {
req.sql.from('escola')
.field('MIN(escola.ano_censo)', 'start_year')
.field('MAX(escola.ano_censo)', 'end_year');
next();
}, query, response('range'));
portalMecSchoolName.get('/years', cache('15 day'), (req, res, next) => {
req.sql.from('escola').
field('DISTINCT escola.ano_censo', 'year');
next();
}, query, response('years'));
portalMecSchoolName.get('/source', (req, res, next) => {
req.sql.from('fonte')
.field('fonte', 'source')
.where('tabela = \'escola\'');
next();
}, query, response('source'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: 'LIKE',
type: 'string',
field: 'nome',
table: 'municipio'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'sigla',
resultField: 'state_name',
where: {
relation: 'LIKE',
type: 'string',
field: 'sigla',
table: 'estado'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
});
portalMecSchoolName.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
if(("state" in req.filter) && ("city" in req.filter)) {
console.log(req.filter);
req.sql.from('escola')
.field('DISTINCT escola.id')
.field('escola.nome_escola', 'name')
.join('municipio', null, 'municipio.id=escola.municipio_id')
.field('municipio.nome', 'city_name')
.join('estado', null, 'estado.id=escola.estado_id')
.field('estado.sigla', 'state_name')
delete req.filter.state;
delete req.filter.city;
next();
}
else {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
}, query, response('portalMec_schoolName'));
module.exports = portalMecSchoolName;
......@@ -219,7 +219,44 @@ rqf.addField({
field: 'ano_censo',
table: 'escola'
}
});
}).addField({
name: 'search',
field: true,
where: true
}).addValueToField({
name: 'city_name',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
dontGroup: true,
where: {
relation: 'LIKE',
type: 'string',
field: 'nome'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}, 'search')
.addValueToField({
name: 'state_name',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
dontGroup: true,
where: {
relation: 'LIKE',
type: 'string',
field: 'sigla'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
}, 'search');
rqfCount.addField({
name: 'filter',
......@@ -464,13 +501,7 @@ rqfCount.addField({
}
});
schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) {
res.status(400);
next({
status: 400,
message: 'Wrong/No filter specified'
});
}
req.sql.from('escola')
.field('escola.id')
.field('escola.ano_censo', 'year')
......
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