From 84e7b42da1f80a6694fe8b05332c04699439c462 Mon Sep 17 00:00:00 2001
From: fgs21 <fgs21@inf.ufpr.br>
Date: Fri, 9 Feb 2024 09:29:33 -0300
Subject: [PATCH] [ADD] Trying to work with filters with id2str (filter
 newPnadAdmDependency added)

---
 src/libs/convert/newPnadAdmDependency.js | 30 ++++++++++++++++++++++++
 src/libs/middlewares/id2str.js           |  7 ++++--
 src/libs/routes_v1/newPnad.js            | 17 +++++++-------
 3 files changed, 44 insertions(+), 10 deletions(-)
 create mode 100644 src/libs/convert/newPnadAdmDependency.js

diff --git a/src/libs/convert/newPnadAdmDependency.js b/src/libs/convert/newPnadAdmDependency.js
new file mode 100644
index 00000000..35d652d1
--- /dev/null
+++ b/src/libs/convert/newPnadAdmDependency.js
@@ -0,0 +1,30 @@
+/*
+Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre
+Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
+   
+This file is part of simcaq-node.
+
+simcaq-node is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+simcaq-node is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with simcaq-node.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
+module.exports = function newPnadAdmDependency(id) {
+    switch (id) {
+        case 1:
+        return 'Pública';
+        case 2:
+        return 'Privada';
+        case 3:
+        return 'Não frequenta instituição de ensino';
+    }
+};
diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js
index cb549d3d..b3e0c622 100644
--- a/src/libs/middlewares/id2str.js
+++ b/src/libs/middlewares/id2str.js
@@ -101,6 +101,7 @@ const supplyDimension = require(`${libs}/convert/supplyDimension`);
 const type = require(`${libs}/convert/type`);
 const level = require(`${libs}/convert/level`);
 const scholarDependency = require(`${libs}/convert/scholarDependency`);
+const newPnadAdmDependency = require(`${libs}/convert/newPnadAdmDependency`);
 
 const ids = {
     gender_id: gender,
@@ -193,7 +194,8 @@ const ids = {
     supply_dimension_id: supplyDimension,
     type_id: type,
     level_id: level,
-    scholar_dependency_id: scholarDependency
+    scholar_dependency_id: scholarDependency,
+    new_pnad_adm_dependency_id: newPnadAdmDependency
 };
 
 function transform(removeId=false) {
@@ -309,5 +311,6 @@ module.exports = {
     peePorCategoria,
     pee,
     shift,
-    admDependencyPub
+    admDependencyPub,
+    newPnadAdmDependency
 };
diff --git a/src/libs/routes_v1/newPnad.js b/src/libs/routes_v1/newPnad.js
index 20c2c33b..5cf8d5e8 100644
--- a/src/libs/routes_v1/newPnad.js
+++ b/src/libs/routes_v1/newPnad.js
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2016 Centro de Computacao Cientifica e Software Livre
+Copyright (C) 2024 Centro de Computacao Cientifica e Software Livre
 Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
 
 This file is part of simcaq-node.
@@ -86,13 +86,14 @@ PnadNovoApp.get('/instruction_level', (req, res, next) => {
 }, response('instruction_level'));
 
 PnadNovoApp.get('/adm_dependency', (req, res, next) => {
-    req.result = [
-        {id: 1, name: 'Publica'},
-        {id: 2, name: 'Privada'},
-        {id: 3, name: 'Não frequenta instituição de ensino'},
-    ];
+    req.result = []
+    for (let i = 1; i < 4; i++) {
+        req.result.push({
+            id: i, name: id2str.newPnadAdmDependency(i)
+        });
+    }
     next();
-}, response('years_of_study'));
+}, response('adm_dependency'));
 
 rqf.addField({
     name: 'filter',
@@ -176,7 +177,7 @@ rqf.addField({
     name: 'adm_dependency',
     table: 'pnad_novo',
     tableField: 'dependencia_adm',
-    resultField: 'adm_dependency_id',
+    resultField: 'new_pnad_adm_dependency_id',
     where: {
         relation: '=',
         type: 'integer',
-- 
GitLab