From e7f8b99a7d8321ee2482a41cdc2c02a360804af3 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Wed, 12 Apr 2017 10:45:08 -0300
Subject: [PATCH] Routes aux

---
 src/libs/routes/class.js | 91 +++++++++++++++++++++++++++++++++-------
 1 file changed, 77 insertions(+), 14 deletions(-)

diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js
index 92f99a2a..0e3da744 100644
--- a/src/libs/routes/class.js
+++ b/src/libs/routes/class.js
@@ -15,6 +15,54 @@ const response = require(`${libs}/middlewares/response`);
 const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
 
 let rqfCount = new ReqQueryFields();
+// Complete range of the enrollments dataset.
+// Returns a tuple of start and ending years of the complete enrollments dataset.
+classApp.get('/year_range', (req, res, next) => {
+    req.sql.from('matricula')
+    .field('MIN(matricula.ano_censo)', 'start_year')
+    .field('MAX(matricula.ano_censo)', 'end_year');
+    next();
+}, query, response('range'));
+
+classApp.get('/location', (req, res, next) => {
+    req.sql = squel.select()
+    .field('id')
+    .field('descricao', 'name')
+    .from('localizacao');
+    next();
+}, query, response('location'));
+
+// Returns all adm dependencies
+classApp.get('/adm_dependency', (req, res, next) => {
+    req.sql.from('dependencia_adm')
+    .field('id')
+    .field('nome', 'name')
+    .where('id <= 4');
+    next();
+}, query, response('adm_dependency'));
+
+classApp.get('/adm_dependency_detailed', (req, res, next) => {
+    req.sql.from('dependencia_adm')
+    .field('id', 'id')
+    .field('nome', 'name');
+    next();
+}, query, response('adm_dependency_detailed'));
+
+// Returns all periods avaible
+classApp.get('/period', (req, res, next) => {
+    req.sql.from('turma_turno')
+    .field('id')
+    .field('nome', 'name');
+    next();
+}, query, response('period'));
+
+// Returns all educational levels avaible
+classApp.get('/education_level', (req, res, next) => {
+    req.sql.from('etapas_mod_ensino_segmento')
+    .field('id')
+    .field('nome', 'name');
+    next();
+}, query, response('education_level'));
 
 rqfCount.addField({
     name: 'filter',
@@ -86,6 +134,21 @@ rqfCount.addField({
     foreign: 'dependencia_adm_id',
     foreignTable: 'turma'
   }
+}).addValue({
+    name: 'location',
+    table: 'localizacao',
+    tableField: 'descricao',
+    resultField: 'location_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'localizacao_id',
+        foreignTable: 'turma'
+    }
 }).addValue({
   name:'school_level',
   table: 'etapas_mod_ensino_segmento ',
@@ -102,20 +165,20 @@ rqfCount.addField({
     foreignTable: 'turma'
   }
 }).addValue({
-  name:'dependencia_priv',
-  table: 'escola',
-  tableField: 'dependencia_adm_priv',
-  resultField: 'dependencia_adm_priv',
-  where: {
-    relation: '=',
-    type: 'integer',
-    field: 'id'
-  },
-  join: {
-    primary: 'id',
-    foreign: 'escola_id',
-    foreignTable: 'turma'
-  }
+    name: 'adm_dependency_detailed',
+    table: 'dependencia_adm',
+    tableField: 'nome',
+    resultField: 'adm_dependency_detailed_name',
+    where: {
+        relation: '=',
+        type: 'integer',
+        field: 'id'
+    },
+    join: {
+        primary: 'id',
+        foreign: 'dependencia_adm_priv',
+        foreignTable: 'turma'
+    }
 }).addValue({
   name:'period',
   table: 'turma_turno',
-- 
GitLab