Skip to content
Snippets Groups Projects
Commit 6a654073 authored by jpko19's avatar jpko19
Browse files

Add studentsAee rout

parent 5bed3d9f
Branches
Tags
4 merge requests!335Homologa,!334Dev,!331Issue 752 aee,!309Merge new updates into master
const express = require('express');
const studentsAeeApp = 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();
let rqfCount = new ReqQueryFields();
// cubApp.get('/year_range', (req, res, next) => {
// req.sql.from('cub')
// .field('MIN(cub.ano_censo)', 'start_year')
// .field('MAX(cub.ano_censo)', 'end_year');
// next();
// }, query, response('range'));
// cubApp.get('/years', (req, res, next) => {
// req.sql.from('cub')
// .field('DISTINCT cub.ano_censo', 'year');
// next();
// }, query, response('years'));
// cubApp.get('/months', (req, res, next) => {
// req.sql.from('cub')
// .field('DISTINCT cub.mes_censo', 'month');
// next();
// }, query, response('months'));
// cubApp.get('/years_months', (req, res, next) => {
// req.sql.from('cub')
// .field('DISTINCT cub.ano_censo AS "year", cub.mes_censo AS "month"');
// next();
// }, query, response('years_months'));
// cubApp.get('/price_type', (req, res, next) => {
// req.sql.from('cub')
// .field('DISTINCT cub.tipo_preco', 'price_type');
// next();
// }, query, response('price_type'));
rqf.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'state',
table: 'estado',
tableField: ['sigla', 'id'],
resultField: ['sigla_uf', 'cod_uf'],
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'numero_estudantes_aee'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'numero_estudantes_aee'
}
}).addValueToField({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'id',
table: 'numero_estudantes_aee'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'numero_estudantes_aee'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: ['nome', 'id'],
resultField: ['region_name', 'regiao_id'],
where: {
relation: '=',
type: 'integer',
field: 'id',
table: 'numero_estudantes_aee'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'numero_estudantes_aee'
}
}).addValueToField({
name: 'school',
table: 'numero_estudantes_aee',
tableField: 'escola_id',
resultField: 'school_id',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
}).addValueToField({
name: 'locale_id',
table: 'numero_estudantes_aee',
tableField: 'localizacao_id',
resultField: 'locale_id',
where: {
relation: '=',
type: 'integer',
field: 'localizacao_id'
}
}).addValue({
name: 'ethnic_group',
table: 'numero_estudantes_aee',
tableField: 'cor_raca_id',
resultField: 'ethnic_group_id',
where: {
relation: '=',
type: 'integer',
field: 'cor_raca_id'
}
}).addValue({
name: 'adm_dependency',
table: 'numero_estudantes_aee',
tableField: 'dependencia_adm_id',
resultField: 'adm_dependency_id',
where: {
relation: '=',
type: 'integer',
field: 'dependencia_adm_id'
}
}).addValue({
name:'age_range_all',
table: 'numero_estudantes_aee',
tableField: 'faixa_etaria_31_03',
resultField: 'age_range_all_id',
where: {
relation: '=',
type: 'integer',
field: 'faixa_etaria_31_03'
}
}).addValue({
name: 'gender',
table: 'numero_estudantes_aee',
tableField: 'sexo',
resultField: 'gender_id',
where: {
relation: '=',
type: 'integer',
field: 'sexo'
}
}).addValue({
name: 'activity_days',
table: 'numero_estudantes_aee',
tableField: 'dias_atividade',
resultField: 'activity_days_id',
where: {
relation: '=',
type: 'integer',
field: 'dias_atividade'
}
}).addField({
name: 'special_service',
table: 'numero_estudantes_aee',
tableField: 'disc_atendimento_especiais',
resultField: 'special_service_id',
where: {
relation: '=',
type: 'integer',
field: 'disc_atendimento_especiais'
}
});
studentsAeeApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
req.sql.from('numero_estudantes_aee')
.field('ano_censo')
.field('COUNT(distinct id_aluno)')
.group('ano_censo')
.order('ano_censo')
next();
}, query, id2str.transform(), response('studentsAee'));
module.exports = studentsAeeApp;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment