From 4b51d5f7db32f4f6a362c56b607903f17f839e26 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Thu, 13 Apr 2017 09:23:48 -0300
Subject: [PATCH] Add filter and fix year_range

---
 src/libs/routes/class.js | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/src/libs/routes/class.js b/src/libs/routes/class.js
index 36c2b778..dc0f0258 100644
--- a/src/libs/routes/class.js
+++ b/src/libs/routes/class.js
@@ -18,9 +18,9 @@ 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');
+    req.sql.from('turma')
+    .field('MIN(turma.ano_censo)', 'start_year')
+    .field('MAX(turma.ano_censo)', 'end_year');
     next();
 }, query, response('range'));
 
@@ -119,6 +119,26 @@ rqfCount.addField({
         foreign: 'regiao_id',
         foreignTable: 'turma'
     }
+}).addValue({
+    name: 'min_year',
+    table: 'turma',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '>=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
+}).addValue({
+    name: 'max_year',
+    table: 'turma',
+    tableField: 'ano_censo',
+    resultField: 'year',
+    where: {
+        relation: '<=',
+        type: 'integer',
+        field: 'ano_censo'
+    }
 }).addValue({
     name:'adm_dependency',
     table: 'dependencia_adm',
-- 
GitLab