From aecdc4a316ee30c06969f99060c4261490604a76 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fcerd15@inf.ufpr.br> Date: Tue, 13 Oct 2020 11:07:29 -0300 Subject: [PATCH] Add university local offer route --- src/libs/routes/api.js | 3 + src/libs/routes/teacher.js | 2 - src/libs/routes/universityLocalOffer.js | 143 ++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 src/libs/routes/universityLocalOffer.js diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index bb690b86..c96266b0 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -126,6 +126,8 @@ const location = require(`${libs}/routes/location`); const disciplines = require(`${libs}/routes/disciplines`); +const universityLocalOffer = require(`${libs}/routes/universityLocalOffer`); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -180,4 +182,5 @@ api.use('/mesoregion', mesoregion); api.use('/microregion', microregion); api.use('/location', location); api.use('/disciplines', disciplines); +api.use('/universityLocalOffer', universityLocalOffer); module.exports = api; diff --git a/src/libs/routes/teacher.js b/src/libs/routes/teacher.js index 85cd3b03..b2a4dc4e 100644 --- a/src/libs/routes/teacher.js +++ b/src/libs/routes/teacher.js @@ -204,8 +204,6 @@ teacherApp.get('/pos_training', (req, res, next) => { next(); }, response('pos_training')); ->>>>>>> origin/issue/694 - rqf.addField({ name: 'filter', field: false, diff --git a/src/libs/routes/universityLocalOffer.js b/src/libs/routes/universityLocalOffer.js new file mode 100644 index 00000000..36cc7481 --- /dev/null +++ b/src/libs/routes/universityLocalOffer.js @@ -0,0 +1,143 @@ +''/* +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 universityLocalOfferApp = 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 cache = require('apicache').options({ debug: config.debug, statusCodes: {include: [200]} }).middleware; + +const addMissing = require(`${libs}/middlewares/addMissing`); + +let rqf = new ReqQueryFields(); + +universityLocalOfferApp.use(cache('15 day')); + +rqf.addField({ + name: 'filter', + field: false, + where: true +}).addField({ + name: 'dims', + field: true, + where: false +}).addValue({ + name: 'city', + table: 'municipio', + tableField: ['nome', 'id'], + resultField: ['city_name', 'city_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_municipio', + table: 'localoferta_ens_superior' + }, + join: { + primary: 'id', + foreign: 'cod_municipio', + foreignTable: 'localoferta_ens_superior' + } +}).addValue({ + name: 'region', + table: 'regiao', + tableField: ['nome', 'id'], + resultField: ['region_name', 'region_id'], + where: { + relation: 'LIKE', + type: 'string', + field: 'id' + }, + join: { + primary: 'nome', + foreign: 'nome_regiao_ies', + foreignTable: 'localoferta_ens_superior' + } + +}).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', 'id'], + resultField: ['state_name', 'state_id'], + where: { + relation: '=', + type: 'integer', + field: 'cod_uf', + table: '@' + }, + join: { + primary: 'id', + foreign: 'cod_uf', + foreignTable: '@' + } +}); +' +universityLocalOfferApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { + req.sql.from('localoferta_ens_superior') + .field('localoferta_ens_superior.cod_ies', 'id') + .field('localoferta_ens_superior.ano_censo', 'year') + .field('localoferta_ens_superior.nome', 'name') + .field('localoferta_ens_superior.cod_uf', 'state_id') + .field('localoferta_ens_superior.cod_municipio', 'city_id') + .field('localoferta_ens_superior.cod_regiao', 'region_id'); + next(); + +}, query, response('universityLocalOfferApp')); + +module.exports = universityLocalOfferApp; -- GitLab