From 86e05e1f32a9587897746fd225c19878be6d47f8 Mon Sep 17 00:00:00 2001 From: Vytor Calixto <vytorcalixto@gmail.com> Date: Tue, 18 Apr 2017 08:57:41 -0300 Subject: [PATCH] Change /class to use id2str middleware cc: @fce15 --- src/libs/routes/class.js | 69 ++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 46 deletions(-) diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js index dc0f0258..6f7a7457 100644 --- a/src/libs/routes/class.js +++ b/src/libs/routes/class.js @@ -14,6 +14,8 @@ const response = require(`${libs}/middlewares/response`); const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); +const id2str = require(`${libs}/middlewares/id2str`); + let rqfCount = new ReqQueryFields(); // Complete range of the enrollments dataset. // Returns a tuple of start and ending years of the complete enrollments dataset. @@ -141,78 +143,53 @@ rqfCount.addField({ } }).addValue({ name:'adm_dependency', - table: 'dependencia_adm', - tableField: 'id', - resultField: 'adm_dependency_name', + table: 'turma', + tableField: 'dependencia_adm_id', + resultField: 'adm_dependency_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_id', - foreignTable: 'turma' + field: 'adm_dependency_id' } }).addValue({ name: 'location', - table: 'localizacao', - tableField: 'descricao', - resultField: 'location_name', + table: 'turma', + tableField: 'localizacao_id', + resultField: 'location_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'localizacao_id', - foreignTable: 'turma' + field: 'location_id' } }).addValue({ name:'education_level', - table: 'etapas_mod_ensino_segmento ', - tableField: 'id', - resultField: 'education_level_name', + table: 'turma', + tableField: 'etapas_mod_ensino_segmento_id', + resultField: 'education_level_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'etapas_mod_ensino_segmento_id', - foreignTable: 'turma' + field: 'etapas_mod_ensino_segmento_id' } }).addValue({ name: 'adm_dependency_detailed', - table: 'dependencia_adm', - tableField: 'nome', - resultField: 'adm_dependency_detailed_name', + table: 'turma', + tableField: 'dependencia_adm_priv', + resultField: 'adm_dependency_detailed_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'dependencia_adm_priv', - foreignTable: 'turma' + field: 'dependencia_adm_priv' } }).addValue({ name:'period', - table: 'turma_turno', - tableField: 'id', - resultField: 'period_name', + table: 'turma', + tableField: 'turma_turno_id', + resultField: 'period_id', where: { relation: '=', type: 'integer', - field: 'id' - }, - join: { - primary: 'id', - foreign: 'turno', - foreignTable: 'turma' + field: 'turma_turno_id' } }).addValue({ name: 'school', @@ -242,6 +219,6 @@ classApp.get('/', rqfCount.parse(), rqfCount.build(), (req, res, next) => { .order('turma.ano_censo') .where('turma.tipo_turma_id = 0 OR turma.tipo_turma_id = 1 OR turma.tipo_turma_id = 2 OR turma.tipo_turma_id = 3'); next(); -}, query, response('class')); +}, query, id2str.transform(true), response('class')); module.exports = classApp; -- GitLab