diff --git a/.gitignore b/.gitignore index 39490f2624d70d0bf3cd39299466a0ae8cfdd91b..08baf221d197e203575471053f219672305703c4 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ build/* config.json docs/ +.vscode/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index dc8c4b6d8bd52a50299f89730400bdda9ba54e58..f30e795881167ccf8926007b3c2e3a1059fe5c52 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,6 +23,3 @@ run_tests: - gulp test tags: - node - cache: - paths: - - node_modules/ diff --git a/package.json b/package.json index 57bcce2e8ebafd2d9ac8de3f941f0c99e58155ac..05fe1eae53edec73f2feeae28535f9cb3389b347 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "debug": "~2.3.x", "dirty-chai": "^1.2.2", "express": "^4.13.0", - "faker": "^3.1.0", "forever": "^0.15.2", "js2xmlparser": "^2.0.2", "jsonexport": "^2.0.9", diff --git a/src/libs/convert/admDependencyPriv.js b/src/libs/convert/admDependencyPriv.js new file mode 100644 index 0000000000000000000000000000000000000000..62afaa8354d2ebabe30826e66aceeb2a8c036790 --- /dev/null +++ b/src/libs/convert/admDependencyPriv.js @@ -0,0 +1,18 @@ +module.exports = function admDependencyPriv(id) { + switch (id) { + case 1: + return 'Federal'; + case 2: + return 'Estadual'; + case 3: + return 'Municipal'; + case 4: + return 'Privada conveniada'; + case 5: + return 'Privada não conveniada sem fins lucrativos'; + case 6: + return 'Privada não conveniada com fins lucrativos'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/citySize.js b/src/libs/convert/citySize.js new file mode 100644 index 0000000000000000000000000000000000000000..819eb150e8a91e9546cf6935ce7b000b63242789 --- /dev/null +++ b/src/libs/convert/citySize.js @@ -0,0 +1,20 @@ +module.exports = function citySize(id) { + switch (id) { + case 1: + return 'até 5000'; + case 2: + return '5001 - 10000'; + case 3: + return '10001 - 20000'; + case 4: + return '20001 - 50000'; + case 5: + return '50001 - 100000'; + case 6: + return '100001 - 500000'; + case 7: + return 'mais que 500000'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/educationLevelMod.js b/src/libs/convert/educationLevelMod.js index 4ee4b37674e130bfad9d0cf3e0c0e587075e06f5..e334e50bcff1665d2c90d2d8b504930a1019e719 100644 --- a/src/libs/convert/educationLevelMod.js +++ b/src/libs/convert/educationLevelMod.js @@ -23,6 +23,6 @@ module.exports = function educationLevelMod(id) { case 11: return 'Educação Profissional'; default: - return 'Não classificado'; + return 'Não classificada'; } }; diff --git a/src/libs/convert/educationLevelShort.js b/src/libs/convert/educationLevelShort.js index 3d543ee98690179952ab97b3b9a9ad6056741a3f..ee97e956453c30af7ae7d37d60a6e2708b5dab2c 100644 --- a/src/libs/convert/educationLevelShort.js +++ b/src/libs/convert/educationLevelShort.js @@ -15,6 +15,6 @@ module.exports = function educationLevelShort(id) { case 7: return 'EE exclusiva'; default: - return 'Não classificado'; + return 'Não classificada'; } }; diff --git a/src/libs/convert/idhmLevel.js b/src/libs/convert/idhmLevel.js new file mode 100644 index 0000000000000000000000000000000000000000..c9f1845c6147e4f59bbbcf7aaecd5934ac5c8017 --- /dev/null +++ b/src/libs/convert/idhmLevel.js @@ -0,0 +1,16 @@ +module.exports = function idhmLevel(id) { + switch (id) { + case 1: + return 'Muito Baixa'; + case 2: + return 'Baixo'; + case 3: + return 'Médio'; + case 4: + return 'Alto'; + case 5: + return 'Muito Alto'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/incomeLevel.js b/src/libs/convert/incomeLevel.js new file mode 100644 index 0000000000000000000000000000000000000000..c39106843027d91d628ec6bdda664507e660aae8 --- /dev/null +++ b/src/libs/convert/incomeLevel.js @@ -0,0 +1,16 @@ +module.exports = function citySize(id) { + switch (id) { + case 1: + return '1º quintil – 20% menores'; + case 2: + return '2º quintil'; + case 3: + return '3º quintil'; + case 4: + return '4º quintil'; + case 5: + return '5º quintil – 20% maiores'; + default: + return 'Não classificada'; + } +}; diff --git a/src/libs/convert/schoolYear.js b/src/libs/convert/schoolYear.js index 485364c86fef34df51eeaf050870d4e2e38f0202..f6b677ccd7c9ac39b8439504b0495e5d0e6dcbf0 100644 --- a/src/libs/convert/schoolYear.js +++ b/src/libs/convert/schoolYear.js @@ -49,6 +49,6 @@ module.exports = function schoolYear(id) { case 71: return 'Educação Profissional'; default: - return 'Não classificado'; + return 'Não classificada'; } }; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 9304758c47e84a553e37f6c0f9d644addb785208..8bde6b4a6b4865f482ee45a8c8cd78bd566caa99 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -3,6 +3,7 @@ const gender = require(`${libs}/convert/gender`); const period = require(`${libs}/convert/period`); const schoolYear = require(`${libs}/convert/schoolYear`); const admDependency = require(`${libs}/convert/admDependency`); +const admDependencyPriv = require(`${libs}/convert/admDependencyPriv`); const location = require(`${libs}/convert/location`); const ruralLocation = require(`${libs}/convert/ruralLocation`); const ethnicGroup = require(`${libs}/convert/ethnicGroup`); @@ -12,6 +13,9 @@ const educationLevel = require(`${libs}/convert/educationLevel`); const educationLevelMod = require(`${libs}/convert/educationLevelMod`); const educationLevelShort = require(`${libs}/convert/educationLevelShort`); const educationType = require(`${libs}/convert/educationType`); +const citySize = require(`${libs}/convert/citySize`); +const incomeLevel = require(`${libs}/convert/incomeLevel`); +const idhmLevel = require(`${libs}/convert/idhmLevel`); const ids = { gender_id: gender, @@ -21,7 +25,7 @@ const ids = { education_level_mod_id: educationLevelMod, education_level_short_id: educationLevelShort, adm_dependency_id: admDependency, - adm_dependency_detailed_id: admDependency, + adm_dependency_detailed_id: admDependencyPriv, location_id: location, rural_location_id: ruralLocation, ethnic_group_id: ethnicGroup, @@ -56,7 +60,10 @@ const ids = { library_id: booleanVariable, reading_room_id: booleanVariable, water_id: booleanVariable, - education_type_id: educationType + education_type_id: educationType, + income_level_id: incomeLevel, + city_size_id: citySize, + idhm_level_id: idhmLevel }; function transform(removeId=false) { diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 2e7c9a3efd4267a6e75f5e53ed187eebde464e2a..7353dfd144c09add582aab1262ee8e29248c39a2 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -30,6 +30,18 @@ const classroom = require('./classroom'); const teacher = require('./teacher'); +const idhme = require('./idhme'); + +const pibpercapita = require('./pibpercapita') + +const population = require('./population') + +const idhm = require('./idhm'); + +const idhmr = require('./idhmr'); + +const idhml = require('./idhml'); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -46,5 +58,11 @@ api.use('/school', cache('15 day'), school); api.use('/spatial', cache('1 day'), spatial); api.use('/classroom', cache('15 day'), classroom); api.use('/teacher', cache('1 day'), teacher); +api.use('/idhmr', cache('1 day'), idhmr); +api.use('/idhm', cache('1 day'), idhm); +api.use('/idhme', cache('15 day'), idhme); +api.use('/pibpercapita', cache('1 day'), pibpercapita); +api.use('/population', cache('1 day'), population); +api.use('/idhml', cache('1 day'), idhml); module.exports = api; diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js index 382121b5f5f3de1cb47c80b6abc75297846beebc..8dde3a491f2027ea86f97d960686e8fb07c5b186 100644 --- a/src/libs/routes/class.js +++ b/src/libs/routes/class.js @@ -26,6 +26,12 @@ classApp.get('/year_range', (req, res, next) => { next(); }, query, response('range')); +classApp.get('/years', (req, res, next) => { + req.sql.from('turma') + .field('DISTINCT turma.ano_censo', 'year'); + next(); +}, query, response('years')); + classApp.get('/location', (req, res, next) => { req.sql = squel.select() .field('id') @@ -57,7 +63,7 @@ classApp.get('/adm_dependency', (req, res, next) => { }, query, response('adm_dependency')); classApp.get('/adm_dependency_detailed', (req, res, next) => { - req.sql.from('dependencia_adm') + req.sql.from('dependencia_adm_priv') .field('id', 'id') .field('nome', 'name'); next(); @@ -91,7 +97,7 @@ classApp.get('/education_level_mod', (req, res, next) => { classApp.get('/education_level_short', (req, res, next) => { req.result = [ - {id: null, name: 'Não Classificado'}, + {id: null, name: 'Não classificada'}, {id: 1, name: 'Creche'}, {id: 2, name: 'Pré-Escola'}, {id: 3, name: 'Ensino Fundamental - anos iniciais'}, diff --git a/src/libs/routes/classroom.js b/src/libs/routes/classroom.js index 58599f19a8e94761d76a2de3e1f21d56456a17de..3658a587167c24cc3a3afcc37e0dde4b4808a2ba 100644 --- a/src/libs/routes/classroom.js +++ b/src/libs/routes/classroom.js @@ -27,6 +27,12 @@ classroomApp.get('/year_range', (req, res, next) => { next(); }, query, response('range')); +classroomApp.get('/years', (req, res, next) => { + req.sql.from('escola') + .field('DISTINCT escola.ano_censo', 'year'); + next(); +}, query, response('years')); + classroomApp.get('/adm_dependency', (req, res, next) => { req.sql.from('dependencia_adm') .field('id') @@ -183,7 +189,6 @@ rqf.addField({ }); classroomApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - console.log(req.filter); req.sql.from('escola') .field('SUM(escola.num_salas)', 'total') .field("'Brasil'", 'name') diff --git a/src/libs/routes/enrollment.js b/src/libs/routes/enrollment.js index b7dc9b170db18b294fcdb222d4f9f24a88980e25..a8523ba967de2296e86297e5bb52500eae2cc63d 100644 --- a/src/libs/routes/enrollment.js +++ b/src/libs/routes/enrollment.js @@ -27,6 +27,12 @@ enrollmentApp.get('/year_range', (req, res, next) => { next(); }, query, response('range')); +enrollmentApp.get('/years', (req, res, next) => { + req.sql.from('matricula') + .field('DISTINCT matricula.ano_censo', 'year'); + next(); +}, query, response('years')); + enrollmentApp.get('/location', (req, res, next) => { req.sql = squel.select() .field('id') @@ -74,7 +80,7 @@ enrollmentApp.get('/education_level_mod', (req, res, next) => { enrollmentApp.get('/education_level_short', (req, res, next) => { req.result = [ - {id: null, name: 'Não Classificado'}, + {id: null, name: 'Não classificada'}, {id: 1, name: 'Creche'}, {id: 2, name: 'Pré-Escola'}, {id: 3, name: 'Ensino Fundamental - anos iniciais'}, @@ -96,7 +102,7 @@ enrollmentApp.get('/adm_dependency', (req, res, next) => { }, query, response('adm_dependency')); enrollmentApp.get('/adm_dependency_detailed', (req, res, next) => { - req.sql.from('dependencia_adm') + req.sql.from('dependencia_adm_priv') .field('id', 'id') .field('nome', 'name'); next(); diff --git a/src/libs/routes/idhm.js b/src/libs/routes/idhm.js new file mode 100644 index 0000000000000000000000000000000000000000..16f225a7c9aa0d97d869d3e2e300f2dabc0356cd --- /dev/null +++ b/src/libs/routes/idhm.js @@ -0,0 +1,186 @@ +const express = require('express'); + +const idhmApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +idhmApp.get('/year_range', (req, res, next) => { + req.sql.from('adh_idh') + .field('MIN(adh_idh.ano_censo)', 'start_year') + .field('MAX(adh_idh.ano_censo)', 'end_year'); + next(); +}, query, (req, res, next) => { + req.sql.from('adh_idh_uf') + .field('MIN(adh_idh_uf.ano_censo)', 'start_year') + .field('MAX(adh_idh_uf.ano_censo)', 'end_year'); + req.old_result = req.result; + next(); +}, query, (req, res, next) => { + // console.log(req.old_result[0].start_year); + // console.log(req.result[0].start_year); + if (req.old_result[0].start_year < req.result[0].start_year) { + req.result[0].start_year = req.old_result[0].start_year; + } + if (req.old_result[0].end_year > req.result[0].end_year) { + req.result[0].end_year = req.old_result[0].old_result; + } + next(); +}, query, response('range')); + +idhmApp.get('/years', (req, res, next) => { + req.sql.from('adh_idh') + .field('DISTINCT adh_idh.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + req.oldResult = req.result; + + req.sql = squel.select(); + + req.sql.from('adh_idh_uf') + .field('DISTINCT adh_idh_uf.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + let result = Object.assign(req.oldResult, req.result); + req.result = result; + next(); +}, response('years')); + +idhmApp.get('/IDHM_level', (req, res, next) => { + req.result = [ + {id: null, name: 'Não classificada'}, + {id: 1, name: 'Muito Baixa'}, + {id: 2, name: 'Baixo'}, + {id: 3, name: 'Médio'}, + {id: 4, name: 'Alto'}, + {id: 5, name: 'Muito Alto'} + ]; + next(); +}, response('IDHM_level')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'adh_idh' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'adh_idh' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: '@' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: '@' + } +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'idhm_level', + table: '@', + tableField: 'idhm_nivel', + resultField: 'idhm_level_id', + where: { + relation: '=', + type: 'integer', + table: '@', + field: 'idhm_nivel' + } +}); + + +idhmApp.get('/', rqf.parse(), (req, res, next) => { + log.debug(req.sql.toParam()); + if((Object.keys(req.filter).length === 0) && (Object.keys(req.dims).length === 0)) { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + if ("state" in req.filter && !("city" in req.filter)) { + req.sql.from('adh_idh_uf') + .field('adh_idh_uf.idhm', 'total') + .field('adh_idh_uf.ano_censo', 'year') + .field('adh_idh_uf.estado_id', 'state_id') + .group('adh_idh_uf.idhm') + .group('adh_idh_uf.ano_censo') + .group('adh_idh_uf.estado_id') + } else if ("city" in req.filter) { + req.sql.from('adh_idh') + .field('adh_idh.idhm', 'total') + .field('adh_idh.ano_censo', 'year') + .field('adh_idh.municipio_id', 'city_id') + .field('adh_idh.estado_id', 'city_id') + .group('adh_idh.idhm') + .group('adh_idh.ano_censo') + .group('adh_idh.municipio_id') + .group('adh_idh.estado_id') + } else { + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + next(); +}, rqf.build(), query, id2str.transform(), response('idhm')); + +module.exports = idhmApp; diff --git a/src/libs/routes/idhme.js b/src/libs/routes/idhme.js new file mode 100644 index 0000000000000000000000000000000000000000..2a68bc9aedf20edaa01f7974dc6c8fd57e1517d7 --- /dev/null +++ b/src/libs/routes/idhme.js @@ -0,0 +1,150 @@ +const express = require('express'); + +const idhmeApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +let rqf = new ReqQueryFields(); + +idhmeApp.get('/year_range', (req, res, next) => { + req.sql.from('adh_idh') + .field('MIN(adh_idh.ano_censo)', 'start_year') + .field('MAX(adh_idh.ano_censo)', 'end_year'); + next(); +}, query, (req, res, next) => { + req.sql.from('adh_idh_uf') + .field('MIN(adh_idh_uf.ano_censo)', 'start_year') + .field('MAX(adh_idh_uf.ano_censo)', 'end_year'); + req.old_result = req.result; + next(); +}, query, (req, res, next) => { + // console.log(req.old_result[0].start_year); + // console.log(req.result[0].start_year); + if (req.old_result[0].start_year < req.result[0].start_year) { + req.result[0].start_year = req.old_result[0].start_year; + } + if (req.old_result[0].end_year > req.result[0].end_year) { + req.result[0].end_year = req.old_result[0].old_result; + } + next(); +}, query, response('range')); + +idhmeApp.get('/years', (req, res, next) => { + req.sql.from('adh_idh') + .field('DISTINCT adh_idh.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + req.oldResult = req.result; + + req.sql = squel.select(); + + req.sql.from('adh_idh_uf') + .field('DISTINCT adh_idh_uf.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + let result = Object.assign(req.oldResult, req.result); + req.result = result; + next(); +}, response('years')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'adh_idh' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'adh_idh' + } +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: '@' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: '@' + } +}); + +idhmeApp.get('/', rqf.parse(), (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' + }); + } + + if (!("state" in req.filter) && !("city" in req.filter)) { + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + if ("city" in req.filter) { + req.sql.from('adh_idh') + .field('adh_idh.idhm_e', 'total') + .field('adh_idh.ano_censo', 'year') + .field('adh_idh.municipio_id', 'city_id'); + } else { + // console.log("sim"); + req.sql.from('adh_idh_uf') + .field('adh_idh_uf.idhm_e', 'total') + .field('adh_idh_uf.ano_censo', 'year') + .field('adh_idh_uf.estado_id', 'state_id'); + } + next(); +}, rqf.build(), query, response('idhme')); + +module.exports = idhmeApp; diff --git a/src/libs/routes/idhml.js b/src/libs/routes/idhml.js new file mode 100644 index 0000000000000000000000000000000000000000..5ba3e12b704a0eb3ac3ae7c5119dcdf0093db21d --- /dev/null +++ b/src/libs/routes/idhml.js @@ -0,0 +1,149 @@ +const express = require('express'); + +const idhmlApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const id2str = require(`${libs}/middlewares/id2str`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +let rqf = new ReqQueryFields(); + +idhmlApp.get('/year_range', (req, res, next) => { + req.sql.from('adh_idh') + .field('MIN(adh_idh.ano_censo)', 'start_year') + .field('MAX(adh_idh.ano_censo)', 'end_year'); + next(); +}, query, (req, res, next) => { + req.sql.from('adh_idh_uf') + .field('MIN(adh_idh_uf.ano_censo)', 'start_year') + .field('MAX(adh_idh_uf.ano_censo)', 'end_year'); + req.old_result = req.result; + next(); +}, query, (req, res, next) => { + // console.log(req.old_result[0].start_year); + // console.log(req.result[0].start_year); + if (req.old_result[0].start_year < req.result[0].start_year) { + req.result[0].start_year = req.old_result[0].start_year; + } + if (req.old_result[0].end_year > req.result[0].end_year) { + req.result[0].end_year = req.old_result[0].old_result; + } + next(); +}, query, response('range')); + +idhmlApp.get('/years', (req, res, next) => { + req.sql.from('adh_idh') + .field('DISTINCT adh_idh.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + req.oldResult = req.result; + + req.sql = squel.select(); + + req.sql.from('adh_idh_uf') + .field('DISTINCT adh_idh_uf.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + let result = Object.assign(req.oldResult, req.result); + req.result = result; + next(); +}, response('years')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'adh_idh' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'adh_idh' + } +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: '@' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: '@' + } +}); + +idhmlApp.get('/', rqf.parse(), (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' + }); + } + if (!("state" in req.filter) && !("city" in req.filter)) { + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + if ("city" in req.filter) { + req.sql.from('adh_idh') + .field('adh_idh.idhm_l', 'total') + .field('adh_idh.ano_censo', 'year') + .field('adh_idh.municipio_id', 'city_id'); + } else { + // console.log("sim"); + req.sql.from('adh_idh_uf') + .field('adh_idh_uf.idhm_l', 'total') + .field('adh_idh_uf.ano_censo', 'year') + .field('adh_idh_uf.estado_id', 'state_id'); + } + next(); +}, rqf.build(), query, response('idhml')); + +module.exports = idhmlApp; diff --git a/src/libs/routes/idhmr.js b/src/libs/routes/idhmr.js new file mode 100644 index 0000000000000000000000000000000000000000..c8a0cba078bfc420973438f230209534d495f715 --- /dev/null +++ b/src/libs/routes/idhmr.js @@ -0,0 +1,156 @@ +const express = require('express'); + +const idhmrApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +idhmrApp.get('/year_range', (req, res, next) => { + req.sql.from('adh_idh') + .field('MIN(adh_idh.ano_censo)', 'start_year') + .field('MAX(adh_idh.ano_censo)', 'end_year'); + next(); +}, query, (req, res, next) => { + req.sql.from('adh_idh_uf') + .field('MIN(adh_idh_uf.ano_censo)', 'start_year') + .field('MAX(adh_idh_uf.ano_censo)', 'end_year'); + req.old_result = req.result; + next(); +}, query, (req, res, next) => { + // console.log(req.old_result[0].start_year); + // console.log(req.result[0].start_year); + if (req.old_result[0].start_year < req.result[0].start_year) { + req.result[0].start_year = req.old_result[0].start_year; + } + if (req.old_result[0].end_year > req.result[0].end_year) { + req.result[0].end_year = req.old_result[0].old_result; + } + next(); +}, query, response('range')); + +idhmrApp.get('/years', (req, res, next) => { + req.sql.from('adh_idh') + .field('DISTINCT adh_idh.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + req.oldResult = req.result; + + req.sql = squel.select(); + + req.sql.from('adh_idh_uf') + .field('DISTINCT adh_idh_uf.ano_censo', 'year'); + next(); +}, query, (req, res, next) => { + let result = Object.assign(req.oldResult, req.result); + req.result = result; + next(); +}, response('years')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'adh_idh' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'adh_idh' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: '@' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: '@' + } +}).addValue({ + name: 'min_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: '@', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + table: '@', + field: 'ano_censo' + } +}); + +idhmrApp.get('/', rqf.parse(), (req, res, next) => { + log.debug(req.sql.toParam()); + if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0 ) { + res.status(400); + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + if ("state" in req.filter && !("city" in req.filter)) { + req.sql.from('adh_idh_uf') + .field('adh_idh_uf.idhm_r', 'total') + .field('adh_idh_uf.ano_censo', 'year') + .field('adh_idh_uf.estado_id', 'state_id'); + } else if ("city" in req.filter) { + req.sql.from('adh_idh') + .field('adh_idh.idhm_r', 'total') + .field('adh_idh.ano_censo', 'year') + .field('adh_idh.municipio_id', 'city_id') + .field('adh_idh.estado_id', 'estado_id'); + } else { + next({ + status: 400, + message: 'Wrong/No filter specified' + }); + } + + next(); +}, rqf.build(),query, response('idhmr')); + +module.exports = idhmrApp; diff --git a/src/libs/routes/pibpercapita.js b/src/libs/routes/pibpercapita.js new file mode 100644 index 0000000000000000000000000000000000000000..aff7a7dfafb757815e4636c042d6b7e7bf8a8761 --- /dev/null +++ b/src/libs/routes/pibpercapita.js @@ -0,0 +1,128 @@ +const express = require('express'); + +const pibpercapitaApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +pibpercapitaApp.get('/year_range', (req, res, next) => { + req.sql.from('ibge_pib') + .field('MIN(ibge_pib.ano_censo)', 'start_year') + .field('MAX(ibge_pib.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +pibpercapitaApp.get('/years', (req, res, next) => { + req.sql.from('ibge_pib'). + field('DISTINCT ibge_pib.ano_censo', 'year'); + next(); +}, query, response('years')); + +pibpercapitaApp.get('/income_level', (req, res, next) => { + req.result = [ + {id: 1, name: "1º quintil – 20% menores"}, + {id: 2, name: "2º quintil"}, + {id: 3, name: "3º quintil"}, + {id: 4, name: "4º quintil"}, + {id: 5, name: "5º quintil – 20% maiores"}, + ]; + next(); +}, response('income_level')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'ibge_pib' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'ibge_pib' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'ibge_pib' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'ibge_pib' + } +}).addValue({ + name: 'min_year', + table: 'ibge_pib', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'ibge_pib', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'income_level', + table: 'ibge_pib', + tableField: 'nivel_renda_per_capita', + resultField: 'income_level_id', + where: { + relation: '=', + type: 'integer', + field: 'nivel_renda_per_capita' + } +}); + +pibpercapitaApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + log.debug(req.sql.toParam()); + req.sql.from('ibge_pib') + .field('SUM(ibge_pib.pib)/SUM(ibge_pib.populacao)', 'total') + .field('ibge_pib.ano_censo', 'year') + .group('ibge_pib.ano_censo') + .order('ibge_pib.ano_censo') + + next(); +}, query, id2str.transform(false), response('pibpercapita')); + +module.exports = pibpercapitaApp; diff --git a/src/libs/routes/population.js b/src/libs/routes/population.js new file mode 100644 index 0000000000000000000000000000000000000000..3d05c3d0d06fd1630bdcf86df75ec4fba05eaa01 --- /dev/null +++ b/src/libs/routes/population.js @@ -0,0 +1,147 @@ +const express = require('express'); + +const populationApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const log = require(`${libs}/log`)(module); + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const id2str = require(`${libs}/middlewares/id2str`); + +let rqf = new ReqQueryFields(); + +populationApp.get('/year_range', (req, res, next) => { + req.sql.from('ibge_populacao') + .field('MIN(ibge_populacao.ano_censo)', 'start_year') + .field('MAX(ibge_populacao.ano_censo)', 'end_year'); + next(); +}, query, response('range')); + +populationApp.get('/years', (req, res, next) => { + req.sql.from('ibge_populacao'). + field('DISTINCT ibge_populacao.ano_censo', 'year'); + next(); +}, query, response('years')); + +populationApp.get('/city_size', (req, res, next) => { + req.result = [ + {id: 1, name: "até 5000"}, + {id: 2, name: "5001 - 10000"}, + {id: 3, name: "10001 - 20000"}, + {id: 4, name: "20001 - 50000"}, + {id: 5, name: "50001 - 100000"}, + {id: 6, name: "100001 - 500000"}, + {id: 7, name: "mais que 500000"} + ]; + next(); +}, response('city_size')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: 'nome', + resultField: 'city_name', + where: { + relation: '=', + type: 'integer', + field: 'municipio_id', + table: 'ibge_populacao' + }, + join: { + primary: 'id', + foreign: 'municipio_id', + foreignTable: 'ibge_populacao' + } +}).addValue({ + name: 'state', + table: 'estado', + tableField: 'nome', + resultField: 'state_name', + where: { + relation: '=', + type: 'integer', + field: 'estado_id', + table: 'ibge_populacao' + }, + join: { + primary: 'id', + foreign: 'estado_id', + foreignTable: 'ibge_populacao' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: 'nome', + resultField: 'region_name', + where: { + relation: '=', + type: 'integer', + field: 'regiao_id', + table: 'ibge_populacao' + }, + join: { + primary: 'id', + foreign: 'regiao_id', + foreignTable: 'ibge_populacao' + } +}).addValue({ + name: 'min_year', + table: 'ibge_populacao', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '>=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'max_year', + table: 'ibge_populacao', + tableField: 'ano_censo', + resultField: 'year', + where: { + relation: '<=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'city_size', + table: 'ibge_populacao', + tableField: 'porte', + resultField: 'city_size_id', + where: { + relation: '=', + type: 'integer', + field: 'porte' + } +}); + +populationApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + log.debug(req.sql.toParam()); + log.debug(req.dims); + req.sql.from('ibge_populacao') + .field('SUM(ibge_populacao.populacao)', 'total') + .field('ibge_populacao.ano_censo', 'year') + .group('ibge_populacao.ano_censo') + .order('ibge_populacao.ano_censo') + + next(); +}, query, id2str.transform(false), response('population')); + +module.exports = populationApp; diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js index 5320c29fbb3810d6c0b8b71492bbfe64e25c208a..fce424982290c9fa7b5847d6dae8c0937f9c7e2d 100644 --- a/src/libs/routes/school.js +++ b/src/libs/routes/school.js @@ -25,6 +25,12 @@ schoolApp.get('/year_range', (req, res, next) => { next(); }, query, response('range')); +schoolApp.get('/years', (req, res, next) => { + req.sql.from('escola'). + field('DISTINCT escola.ano_censo', 'year'); + next(); +}, query, response('years')); + schoolApp.get('/location', (req, res, next) => { req.result = [ {id: 1, name: 'Urbana'}, @@ -54,7 +60,7 @@ schoolApp.get('/adm_dependency', (req, res, next) => { }, query, response('adm_dependency')); schoolApp.get('/adm_dependency_detailed', (req, res, next) => { - req.sql.from('dependencia_adm') + req.sql.from('dependencia_adm_priv') .field('id', 'id') .field('nome', 'name'); next(); @@ -488,7 +494,7 @@ rqfCount.addField({ } }).addValue({ name: 'adm_dependency_detailed', - table: 'dependencia_adm', + table: 'dependencia_adm_priv', tableField: 'nome', resultField: 'adm_dependency_detailed_name', where: { @@ -848,7 +854,6 @@ rqfCount.addField({ // SELECT COUNT(escola.id) AS "total", 'Brasil' AS "name", escola.ano_censo AS "year" FROM escola WHERE (escola.biblioteca = ? OR escola.sala_leitura = ? OR escola.biblioteca_sala_leitura) AND (escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1) GROUP BY escola.ano_censo ORDER BY escola.ano_censo ASC schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { - console.log(req.filter); if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) { res.status(400); next({ diff --git a/src/libs/routes/teacher.js b/src/libs/routes/teacher.js index 12cd08c12d98571bffd986478491a06de023e111..294417dd1af605ae7a17a64d504269209121acd1 100644 --- a/src/libs/routes/teacher.js +++ b/src/libs/routes/teacher.js @@ -26,6 +26,12 @@ teacherApp.get('/year_range', (req, res, next) => { next(); }, query, response('range')); +teacherApp.get('/years', (req, res, next) => { + req.sql.from('docente'). + field('DISTINCT docente.ano_censo', 'year'); + next(); +}, query, response('years')); + teacherApp.get('/adm_dependency_detailed', (req, res, next) => { req.sql.from('dependencia_adm') .field('id', 'id') @@ -50,7 +56,7 @@ teacherApp.get('/education_level_mod', (req, res, next) => { teacherApp.get('/education_level_short', (req, res, next) => { req.result = [ - {id: null, name: 'Não Classificado'}, + {id: null, name: 'Não classificada'}, {id: 1, name: 'Creche'}, {id: 2, name: 'Pré-Escola'}, {id: 3, name: 'Ensino Fundamental - anos iniciais'}, @@ -309,7 +315,7 @@ teacherApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { .field("'Brasil'", 'name') .field('docente.ano_censo', 'year') .from('docente') - .join('turma', null, 'docente.turma_id=turma.id') + .join('turma', null, 'docente.turma_id=turma.id AND docente.ano_censo=turma.ano_censo') .group('docente.ano_censo') .order('docente.ano_censo') .where('(docente.tipo_docente = 1 OR docente.tipo_docente = 5) AND (turma.tipo_turma_id <= 3)'); diff --git a/src/libs/routes/user.js b/src/libs/routes/user.js index 4e4dd72f2cf3ef2dd854f7ccaa4dacf9a642d9d2..0d04dfd0f799bbda44eb0dfccc5d9f5ea42f7fcd 100644 --- a/src/libs/routes/user.js +++ b/src/libs/routes/user.js @@ -12,6 +12,8 @@ const User = require(`${libs}/models/user`); const jwt = require('jwt-simple'); +const response = require(`${libs}/middlewares/response`); + const required_fields = ["email", "password", "name", "cpf", "schooling", "segment", "role", "institution_name", "state", "city"]; @@ -20,6 +22,51 @@ function emailSyntax(email) { return regex.test(email); } +userApp.get('/schooling', (req, res, next) => { + req.result = [ + 'Não estudou', + 'Ensino Fundamental Incompleto', + 'Ensino Fundamental Completo', + 'Ensino Médio', + 'Graduação', + 'Mestrado', + 'Doutorado' + ]; + next(); +}, response('schooling')); + +userApp.get('/segment', (req, res, next) => { + req.result = [ + 'Gestores e equipe gestora das secretarias e ministério da Educação', + 'Gestores dos órgãos de planejamento e finanças (das três esferas de governo)', + 'Agentes do poder legislativo', + 'Agentes dos conselhos de educação', + 'Profissionais da educação', + 'Sindicato', + 'Sociedade civil interessada no financiamento da Educação Básica de qualidade', + 'Comunidade acadêmica', + 'Imprensa', + 'Outro [citar segmento]' + ]; + next(); +}, response('segment')); + +userApp.get('/role', (req, res, next) => { + req.result = [ + {"Gestores e equipe gestora das secretarias e ministério da Educação" : ["Dirigente municipal, estadual e federal", "Secretário do MEC", "Servidor da área de planejamento educacional", "Membro de associação de gestores (Ex. Undime, Consed, etc)", "Outro [citar função]"]}, + {"Gestores dos órgãos de planejamento e finanças (das três esferas de governo)" : ["Equipe gestora dos órgãos de planejamento", "Equipe gestora dos órgãos de finanças", "Outro [citar função]"]}, + {"Agentes do poder legislativo" : ["Parlamentar", "Assessor/a parlamentar", "Auditor/a dos tribunais de conta", "Conselheiro/a de tribunais de conta.", "Outro [citar função]"]}, + {"Agentes dos conselhos de educação" : ["Conselheiro/a municipais, estaduais e federais", "Conselheiro/a do Fundeb", "Outro [citar função]"]}, + {"Profissionais da educação" : ["Professor/a da Educação Básica", "Profissional da educação não-docente", "Outro [citar função]"]}, + {"Sindicato" : ["Agente de sindicatos"]}, + {"Sociedade civil interessada no financiamento da Educação Básica de qualidade" : ["Membro de fóruns educacionais", "Membro de ONGs e demais entidades sem fins lucrativos", "Estudante da educação básica e membro de entidades estudantis", "Pais e membros de entidades de pais", "Outro [citar função]"]}, + {"Comunidade acadêmica" : ["Pesquisador/a", "Estudantes de graduação e pós-graduação", "Representantes de entidades de pesquisa (Ex.: ANPED, ANPAE e FINEDUCA)", "Outro [citar função]"]}, + {"Imprensa" : ["Jornalista", "Outro [citar função]"]}, + {"Outro [citar segmento]" : []} + ] + next(); +}, response('role')); + userApp.post('/', (req, res, next) => { if(req.body.email){ if(!emailSyntax(req.body.email)){ diff --git a/src/test/class.js b/src/test/class.js index c6fd205a5c0c48fd72c6d49d1846fc1682269159..8b6039ccf3131139fe4f85fbe50861f52b653b66 100644 --- a/src/test/class.js +++ b/src/test/class.js @@ -110,7 +110,7 @@ describe('request class', () => { it('should list the periods', (done) => { chai.request(server) - .get('/api/v1/enrollment/period') + .get('/api/v1/class/period') .end((err, res) => { res.should.have.status(200); res.should.be.json; diff --git a/src/test/classroom.js b/src/test/classroom.js index bd520cf8b67ad396f8251092bf0a4036bb65e36a..08950d6875fb2bda4562943ef9be6177f748814a 100644 --- a/src/test/classroom.js +++ b/src/test/classroom.js @@ -251,7 +251,7 @@ describe('request classrooms', () => { it('should list classrooms with invalid dimensions', (done) => { chai.request(server) - .get('/api/v1/class?dims=foo,bar') + .get('/api/v1/classroom?dims=foo,bar') .end((err, res) => { res.should.have.status(200); res.should.be.json; diff --git a/src/test/idhm.js b/src/test/idhm.js new file mode 100644 index 0000000000000000000000000000000000000000..210d58187ebd4d3a5860a92ec2ea081a7f6f1e33 --- /dev/null +++ b/src/test/idhm.js @@ -0,0 +1,80 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request idhm', () => { + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/idhm/year_range') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('start_year'); + res.body.result[0].should.have.property('end_year'); + done(); + }); + }); + + it('should list idhm with valid filters', (done) => { + chai.request(server) + .get('/api/v1/idhm?filter=min_year:2000,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + res.body.result[0].should.have.property('state_id'); + done(); + }); + }); + + it('should list idhm with invalid filters', (done) => { + chai.request(server) + .get('/api/v1/idhm?filter=foo:2010,bar:41') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }); + }); + + it('should return 400 with no filters', (done) => { + chai.request(server) + .get('/api/v1/idhm') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }) + }); + +}); diff --git a/src/test/idhme.js b/src/test/idhme.js new file mode 100644 index 0000000000000000000000000000000000000000..285160819ada0b77cde946c97ba56ffa0bcc48fd --- /dev/null +++ b/src/test/idhme.js @@ -0,0 +1,80 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request idhme', () => { + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/idhme/year_range') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('start_year'); + res.body.result[0].should.have.property('end_year'); + done(); + }); + }); + + it('should list idhme with valid filters', (done) => { + chai.request(server) + .get('/api/v1/idhme?filter=min_year:2000,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + res.body.result[0].should.have.property('state_id'); + done(); + }); + }); + + it('should list idhme with invalid filters', (done) => { + chai.request(server) + .get('/api/v1/idhme?filter=foo:2010,bar:41') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }); + }); + + it('should return 400 with no filters', (done) => { + chai.request(server) + .get('/api/v1/idhme') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }) + }); + +}); diff --git a/src/test/idhml.js b/src/test/idhml.js new file mode 100644 index 0000000000000000000000000000000000000000..c3409bb45bb7fb97c95567847b837a9d153cb9ae --- /dev/null +++ b/src/test/idhml.js @@ -0,0 +1,80 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request idhml', () => { + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/idhml/year_range') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('start_year'); + res.body.result[0].should.have.property('end_year'); + done(); + }); + }); + + it('should list idhml with valid filters', (done) => { + chai.request(server) + .get('/api/v1/idhml?filter=min_year:2000,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + res.body.result[0].should.have.property('state_id'); + done(); + }); + }); + + it('should list idhml with invalid filters', (done) => { + chai.request(server) + .get('/api/v1/idhml?filter=foo:2010,bar:41') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }); + }); + + it('should return 400 with no filters', (done) => { + chai.request(server) + .get('/api/v1/idhml') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }) + }); + +}); diff --git a/src/test/idhmr.js b/src/test/idhmr.js new file mode 100644 index 0000000000000000000000000000000000000000..64ac892f21e51aa6c24e8f069d486b2afbb8d51a --- /dev/null +++ b/src/test/idhmr.js @@ -0,0 +1,80 @@ +process.env.NODE_ENV = 'test'; + +const chai = require('chai'); + +const dirtyChai = require('dirty-chai'); + +chai.use(dirtyChai); + +const chaiXml = require('chai-xml'); + +chai.use(chaiXml); + +const chaiHttp = require('chai-http'); + +const assert = chai.assert; + +const expect = chai.expect; + +const should = chai.should(); // actually call the function + +const libs = `${process.cwd()}/libs`; + +const server = require(`${libs}/app`); + +chai.use(chaiHttp); +describe('request idhmr', () => { + it('should list the year range', (done) => { + chai.request(server) + .get('/api/v1/idhmr/year_range') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('start_year'); + res.body.result[0].should.have.property('end_year'); + done(); + }); + }); + + it('should list idhmr with valid filters', (done) => { + chai.request(server) + .get('/api/v1/idhmr?filter=min_year:2000,state:41') + .end((err, res) => { + res.should.have.status(200); + res.should.be.json; + res.body.should.have.property('result'); + res.body.result.should.be.a('array'); + res.body.result[0].should.have.property('total'); + res.body.result[0].should.have.property('year'); + res.body.result[0].should.have.property('state_id'); + done(); + }); + }); + + it('should list idhmr with invalid filters', (done) => { + chai.request(server) + .get('/api/v1/idhmr?filter=foo:2010,bar:41') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }); + }); + + it('should return 400 with no filters', (done) => { + chai.request(server) + .get('/api/v1/idhmr') + .end((err, res) => { + res.should.have.status(400); + res.should.be.json; + res.body.should.have.property('error'); + res.body.error.should.be.equal('Wrong/No filter specified'); + done(); + }) + }); + +}); diff --git a/src/test/schoolCount.js b/src/test/schoolCount.js index 59c100000b03263bab56c12fc895339a08d764f6..b40b408247dcc988e81efc92b882f58618b6913a 100644 --- a/src/test/schoolCount.js +++ b/src/test/schoolCount.js @@ -389,34 +389,6 @@ describe('request schools count', () => { }); }); - it('should list the education begin elementary school', (done) => { - chai.request(server) - .get('/api/v1/school/education_begin_elementary_school') - .end((err, res) => { - res.should.have.status(200); - res.should.be.json; - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('id'); - res.body.result[0].should.have.property('name'); - done(); - }); - }); - - it('should list the education end elementary school', (done) => { - chai.request(server) - .get('/api/v1/school/education_end_elementary_school') - .end((err, res) => { - res.should.have.status(200); - res.should.be.json; - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('id'); - res.body.result[0].should.have.property('name'); - done(); - }); - }); - it('should list the education middle school', (done) => { chai.request(server) .get('/api/v1/school/education_middle_school') @@ -539,21 +511,6 @@ describe('request schools count', () => { }); }); - it('should list school with valid dimensions and filters of states', (done) => { - chai.request(server) - .get('/api/v1/school/count?dims=state&filter=min_year:2015,max_year:2016') - .end((err, res) => { - res.should.have.status(200); - res.should.be.json; - res.body.should.have.property('result'); - res.body.result.should.be.a('array'); - res.body.result[0].should.have.property('state_name'); - res.body.result[0].should.have.property('total'); - res.body.result[0].should.have.property('year'); - done(); - }); - }); - it('should list school with valid dimensions and filters of states', (done) => { chai.request(server) .get('/api/v1/school/count?dims=state,education_professional,education_eja&filter=min_year:2015,max_year:2016')