diff --git a/src/libs/convert/level.js b/src/libs/convert/level.js new file mode 100644 index 0000000000000000000000000000000000000000..e52a331bd7cf9ebd936ded24e2f48fa0c7099388 --- /dev/null +++ b/src/libs/convert/level.js @@ -0,0 +1,32 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function level(id) { + switch(id) { + case 1: + return 'Brasil'; + case 2: + return 'Estadual'; + case 3: + return 'Municipal'; + default: + return 'Não especificado'; + } +} \ No newline at end of file diff --git a/src/libs/convert/type.js b/src/libs/convert/type.js new file mode 100644 index 0000000000000000000000000000000000000000..6ffaf010c52ccdfda27e3ab5a1b51e953cc0930c --- /dev/null +++ b/src/libs/convert/type.js @@ -0,0 +1,30 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +module.exports = function type(id) { + switch(id) { + case 1: + return 'Plano'; + case 2: + return 'Rede'; + default: + return 'Não especificado'; + } +} \ No newline at end of file diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index 8c2b068d68e2abd596e5c54b6dd681dc1bfb7cae..39d819aa13bb2f269b53b9ff39579b12849e5ccb 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -98,6 +98,8 @@ const pee = require(`${libs}/convert/booleanVariable`); const shift = require(`${libs}/convert/shift`); const admDependencyPub = require(`${libs}/convert/admDependencyPub`); const supplyDimension = require(`${libs}/convert/supplyDimension`); +const type = require(`${libs}/convert/type`); +const level = require(`${libs}/convert/level`); const ids = { gender_id: gender, @@ -187,7 +189,9 @@ const ids = { pee_por_categoria: peePorCategoria, pee_id: pee, shift_id: shift, - supply_dimension_id: supplyDimension + supply_dimension_id: supplyDimension, + type_id: type, + level_id: level }; function transform(removeId=false) { diff --git a/src/libs/routes_v2/api.js b/src/libs/routes_v2/api.js index b675c882d03d30de38fe174fc17ae4652688260c..f63dd586e6c554d15bedea845d159b7804e98857 100644 --- a/src/libs/routes_v2/api.js +++ b/src/libs/routes_v2/api.js @@ -152,6 +152,8 @@ const simcaqNewClasses = require(`${libs}/routes_v2/simcaqNewClasses`); const simcaqResult = require(`${libs}/routes_v2/simcaqResult`); +const simcaqNumberOfTeachers = require(`${libs}/routes_v2/simcaqNumberOfTeachers`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API v2 is running' }); }); @@ -219,5 +221,6 @@ api.use('/simcaq_workload', simcaqWorkload); api.use('/simcaq_number_of_employees', simcaqNumberOfEmployees); api.use('/simcaq_new_classes', simcaqNewClasses); api.use('/simcaq_result', simcaqResult); +api.use('/simcaq_number_of_teachers', simcaqNumberOfTeachers); module.exports = api; diff --git a/src/libs/routes_v2/simcaqNumberOfTeachers.js b/src/libs/routes_v2/simcaqNumberOfTeachers.js new file mode 100644 index 0000000000000000000000000000000000000000..00f6d9422317d829973f5581923b79b06d24420b --- /dev/null +++ b/src/libs/routes_v2/simcaqNumberOfTeachers.js @@ -0,0 +1,103 @@ +/* +Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre +Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR + +This file is part of simcaq-node. + +simcaq-node is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +simcaq-node is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with simcaq-node. If not, see <https://www.gnu.org/licenses/>. +*/ + +const express = require('express'); + +const simcaqNumberOfTeachersApp = express.Router(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`).query; + +const response = require(`${libs}/middlewares/response`); + +const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); + +const reqBody = require(`${libs}/middlewares/reqBody`); + +const config = require(`${libs}/config`); + +const cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +let rqf = new ReqQueryFields(); + +const id2str = require(`${libs}/middlewares/id2str`); + +simcaqNumberOfTeachersApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'year', + table: 'simcaq_num_professores', + tableField: 'ano_censo', + where: { + relation: '=', + type: 'integer', + field: 'ano_censo' + } +}).addValue({ + name: 'local_id', + table: 'simcaq_num_professores', + tableField: 'local_id', + where: { + relation: '=', + type: 'integer', + field: 'local_id' + } +}).addValue({ + name: 'level_id', + table: 'simcaq_num_professores', + tableField: 'nivel', + where: { + relation: '=', + type: 'integer', + field: 'nivel' + } +}).addValue({ + name: 'type_id', + table: 'simcaq_num_professores', + tableField: 'tipo', + where: { + relation: '=', + type: 'integer', + field: 'tipo' + } +}); + +simcaqNumberOfTeachersApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('simcaq_num_professores') + .field('total', 'number_of_teachers') + .field('simcaq_num_professores.ano_censo', 'year') + .field('simcaq_num_professores.nivel', 'level_id') + .field('simcaq_num_professores.tipo', 'type_id') + .field('simcaq_num_professores.local_id', 'local_id'); + next(); +}, query, id2str.transform(), response('simcaqNumberOfTeachers')); + +module.exports = simcaqNumberOfTeachersApp;