Skip to content
Snippets Groups Projects
Commit 6694746e authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Start updating enrollment routes

parent 9550c48f
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -8,9 +8,11 @@ const log = require(`${libs}/log`)(module); ...@@ -8,9 +8,11 @@ const log = require(`${libs}/log`)(module);
const squel = require('squel'); const squel = require('squel');
const dbQuery = require('../db/query_exec'); const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`);
const response = require('../middlewares/response'); const dbQuery = require('../db/query_exec');
/** /**
* Complete range of the enrollments dataset * Complete range of the enrollments dataset
...@@ -18,46 +20,19 @@ const response = require('../middlewares/response'); ...@@ -18,46 +20,19 @@ const response = require('../middlewares/response');
* Returns a tuple of start and ending years of the complete enrollments dataset. * Returns a tuple of start and ending years of the complete enrollments dataset.
*/ */
enrollmentApp.get('/year_range', (req, res, next) => { enrollmentApp.get('/year_range', (req, res, next) => {
const yearSql = 'SELECT MIN(t.ano_censo) AS start_year, MAX(t.ano_censo)' req.sql = squel.select().from('turmas').field('MIN(turmas.ano_censo)', 'start_year').field('MAX(turmas.ano_censo)', 'end_year').toParam();
+ 'AS end_year FROM turmas AS t'; next();
}, query, response('range'));
dbQuery(yearSql).then((result) => {
const record = result['0'];
log.debug(record);
req.result = { start_year: record.start_year, end_year: record.end_year };
return response(req, res);
}, (error) => {
log.error(`[${req.originalUrl}] SQL query error: ${error}`);
next('Internal error, request could not be satisfied at this moment. Please, '
+ 'try again later');
});
});
enrollmentApp.get('/education_level', (req, res, next) => { enrollmentApp.get('/education_level', (req, res, next) => {
const edLevelSql = 'SELECT pk_etapa_ensino_id AS id, desc_etapa AS ' req.sql = squel.select().from('etapa_ensino').field('pk_etapa_ensino_id', 'id').field('desc_etapa', 'name').toParam();
+ 'education_level FROM etapa_ensino'; next();
}, query, response('education_level'));
dbQuery(edLevelSql).then((result) => {
req.result = result;
return response(req, res);
}, (error) => {
log.error(`[${req.originalUrl}] SQL query error: ${error}`);
next('Internal error, request could not be satisfied at this moment. Please, '
+ 'try again later');
});
});
enrollmentApp.get('/data', (req, res, next) => { enrollmentApp.get('/data', (req, res, next) => {
const schoolClassSql = 'SELECT * FROM turmas'; req.sql = squel.select().from('turmas').toParam();
dbQuery(schoolClassSql).then((result) => { next();
req.result = result; }, query, response('data'));
return response(req, res);
}, (error) => {
log.error(`[${req.originalUrl}] SQL query error: ${error}`);
next('Internal error, request could not be satisfied at this moment. Please, '
+ 'try again later');
});
});
enrollmentApp.use('/', (req, res, next) => { enrollmentApp.use('/', (req, res, next) => {
const params = req.query; const params = req.query;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment