diff --git a/src/libs/routes/api.js b/src/libs/routes/api.js index 1a901d07b3697444596074e94f6a4527980e5189..35e1d0f51d8c8903a5b4235ae4a8906469c84ebd 100644 --- a/src/libs/routes/api.js +++ b/src/libs/routes/api.js @@ -10,6 +10,8 @@ const region = require('./region'); const city = require('./city'); +const school = require('./school'); + api.get('/', (req, res) => { res.json({ msg: 'SimCAQ API is running' }); }); @@ -19,5 +21,6 @@ api.use('/api/v1/enrollment', enrollment); api.use('/api/v1/state', state); api.use('/api/v1/region', region); api.use('/api/v1/city', city); +api.use('/api/v1/school', school); module.exports = api; diff --git a/src/libs/routes/school.js b/src/libs/routes/school.js new file mode 100644 index 0000000000000000000000000000000000000000..bf3ee4fb1ec97ad326f68f4d536d27776ad64531 --- /dev/null +++ b/src/libs/routes/school.js @@ -0,0 +1,62 @@ +const express = require('express'); + +const schoolApp = express(); + +const libs = `${process.cwd()}/libs`; + +const squel = require('squel'); + +const query = require(`${libs}/middlewares/query`); + +const response = require(`${libs}/middlewares/response`); + +/** + * YOU SHALL NOT PASS + * Esta rota foi desabilitada pois é mais violenta que clube da luta batendo em laranja mecânica + * A api fica sobrecarregada + * Pense na cena do elevador de driver mas o elevador é uma bomba de fusão e demora mais que uma luta do DBz + */ +// schoolApp.get('/', (req, res, next) => { +// req.sql = squel.select().from('escolas') +// .field('pk_escola_id') +// .field('nome_entidade', 'name') +// .field('ano_censo', 'year') +// .field('fk_cod_estado') +// .field('fk_cod_municipio') +// .toParam(); +// next(); +// }, query, response('school')); + +schoolApp.get('/:id', (req, res, next) => { + req.sql = squel.select().from('escolas').where('pk_escola_id = ?', + parseInt(req.params.id, 10)).toParam(); + next(); +}, query, response('school')); + +schoolApp.get('/state/:id', (req, res, next) => { + req.sql = squel.select().from('escolas') + .field('pk_escola_id') + .field('nome_entidade', 'name') + .field('ano_censo', 'year') + .field('fk_cod_estado') + .field('fk_cod_municipio') + .where('fk_cod_estado = ?', + parseInt(req.params.id, 10)) + .toParam(); + next(); +}, query, response('school')); + +schoolApp.get('/city/:id', (req, res, next) => { + req.sql = squel.select().from('escolas') + .field('pk_escola_id') + .field('nome_entidade', 'name') + .field('ano_censo', 'year') + .field('fk_cod_estado') + .field('fk_cod_municipio') + .where('fk_cod_municipio = ?', + parseInt(req.params.id, 10)) + .toParam(); + next(); +}, query, response('school')); + +module.exports = schoolApp;