diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf4d7c507ad363464686e9f6a951c83539b23ca..ce0f1edd653ca85f567c631ac1483f5c0467f870 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 1.13.4 - 2020-06-05 +- Arrangment filter in school indicator 2007-2019 + ## 1.13.3 - 2020-05-21 - Employees Indicator 2007-2019 diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js index e430ff425ca0132bc806b47bb4f7fe25379c56a8..b72df7c78071c3c379abd7fec621c835f95e6586 100644 --- a/src/libs/routes/school.js +++ b/src/libs/routes/school.js @@ -175,6 +175,22 @@ schoolApp.get('/education_eja', cache('15 day'), (req, res, next) => { next(); }, response('education_eja')); + +schoolApp.get('/arrangement', cache('15 day'), (req, res, next) => { + req.result = [ + {id: 0, name: 'Creche'}, + {id: 1, name: 'Pré Escola'}, + {id: 2, name: 'Ensino Fundamental - AI'}, + {id: 3, name: 'Ensino Fundamental - AF'}, + {id: 4, name: 'Ed. Infantil Unificada/Multietapa/Multissérie/Correção fluxo'}, + {id: 5, name: 'Ensino Médio'}, + {id: 6, name: 'Ensino EJA'}, + {id: 7, name: 'Educação Profissional'}, + {id: 8, name: 'Educação Especial Exclusiva'} + ]; + next(); +}, response('arrangement')); + schoolApp.get('/integral_time', cache('15 day'), (req, res, next) => { req.result = [ {id: 0, name: 'Não'}, @@ -345,6 +361,38 @@ rqfCount.addField({ foreign: 'estado_id', foreignTable: 'escola' } +}).addValue({ + name: 'mesoregion', + table: 'municipio', + tableField: ['nome_mesorregiao', 'mesorregiao_id'], + resultField: ['mesoregion_name', 'mesoregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'mesorregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } +}).addValue({ + name: 'microregion', + table: 'municipio', + tableField: ['nome_microrregiao', 'microrregiao_id'], + resultField: ['microregion_name', 'microregion_id'], + where: { + relation: '=', + type: 'integer', + field: 'microrregiao_id', + table: 'municipio' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'escola' + } }).addValue({ name: 'region', table: 'regiao', @@ -563,7 +611,9 @@ schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { next(); }, query, response('school')); -schoolApp.get('/count', cache('15 day'), rqfCount.parse(), rqfCount.build(), (req, res, next) => { +schoolApp.get('/count', cache('15 day'), rqfCount.parse(), (req, res, next) => { + console.log(req.filter); + let arrang = ["arranjo_creche", "arranjo_pre", "arranjo_fundamental_ai", "arranjo_fundamental_af", "arranjo_multietapa", "arranjo_ensino_medio", "ensino_eja", "educacao_profissional", "ensino_especial"]; req.sql.from('escola') .field('COUNT(escola.id)', 'total') @@ -571,8 +621,20 @@ schoolApp.get('/count', cache('15 day'), rqfCount.parse(), rqfCount.build(), (re .field('escola.ano_censo', 'year') .group('escola.ano_censo') .order('escola.ano_censo') - .where('escola.situacao_funcionamento_pareada = 1 AND (escola.ensino_regular = 1 OR escola.ensino_eja=1 or escola.educacao_profissional=1)'); + .where('escola.situacao_funcionamento_pareada = 1 AND (escola.ensino_regular = 1 OR escola.ensino_eja=1 or escola.educacao_profissional=1)') + + //Transforma a query em OR se tiver o filtro do arranjo + if (req.filter.arrangement) { + let arrangementQuery = ""; + for (let i = 0; i < req.filter.arrangement.length - 1; i++) { + arrangementQuery += 'escola.' + arrang[req.filter.arrangement[i]] + ' = 1 OR '; + } + // o ultimo elemento precisa ser sem o OR + arrangementQuery += 'escola.' + arrang[req.filter.arrangement[req.filter.arrangement.length - 1]] + ' = 1'; + req.sql.where('' + arrangementQuery); + } + delete req.filter.arrangement next(); -}, query, id2str.transform(), addMissing(rqfCount), response('school')); +}, rqfCount.build(), query, id2str.transform(), addMissing(rqfCount), response('school')); module.exports = schoolApp;