From 7fc318672eb6c07df103203fb04615746d237bde Mon Sep 17 00:00:00 2001 From: fgs21 <fgs21@inf.ufpr.br> Date: Fri, 9 Feb 2024 10:31:00 -0300 Subject: [PATCH] [ADD] Illieteracy convert file created, and added to id2str --- src/libs/convert/Illiteracy.js | 30 ++++++++++++++++++++++++++++++ src/libs/middlewares/id2str.js | 7 +++++-- src/libs/routes_v1/newPnad.js | 16 ++++++++++------ 3 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 src/libs/convert/Illiteracy.js diff --git a/src/libs/convert/Illiteracy.js b/src/libs/convert/Illiteracy.js new file mode 100644 index 00000000..4f4a8bb2 --- /dev/null +++ b/src/libs/convert/Illiteracy.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 0: + return 'Não'; + case 1: + return 'Sim'; + case 9: + return 'Não se aplica - 14 anos ou menos'; + } +}; diff --git a/src/libs/middlewares/id2str.js b/src/libs/middlewares/id2str.js index b3e0c622..b5fe0974 100644 --- a/src/libs/middlewares/id2str.js +++ b/src/libs/middlewares/id2str.js @@ -102,6 +102,7 @@ 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 Illiteracy = require(`${libs}/convert/Illiteracy`); const ids = { gender_id: gender, @@ -195,7 +196,8 @@ const ids = { type_id: type, level_id: level, scholar_dependency_id: scholarDependency, - new_pnad_adm_dependency_id: newPnadAdmDependency + new_pnad_adm_dependency_id: newPnadAdmDependency, + illiteracy_id: Illiteracy }; function transform(removeId=false) { @@ -312,5 +314,6 @@ module.exports = { pee, shift, admDependencyPub, - newPnadAdmDependency + newPnadAdmDependency, + Illiteracy }; diff --git a/src/libs/routes_v1/newPnad.js b/src/libs/routes_v1/newPnad.js index 022e40bb..b57346a4 100644 --- a/src/libs/routes_v1/newPnad.js +++ b/src/libs/routes_v1/newPnad.js @@ -49,11 +49,15 @@ PnadNovoApp.get('/years', (req, res, next) => { }, query, response('years')); PnadNovoApp.get('/illiteracy', (req, res, next) => { - req.result = [ - {id: 0, name: 'Não'}, - {id: 1, name: 'Sim'}, - {id: 9, name: 'Não se aplica - 14 anos ou menos'} - ]; + req.result = [] + + for (let i = 0; i < 2; i++) { + req.result.push({ + id: i, name: id2str.Illiteracy(i) + }); + + req.result.push({id: 9, name: id2str.Illiteracy(9)}); + } next(); }, response('illiteracy')); @@ -148,7 +152,7 @@ rqf.addField({ name: 'illiteracy', table: 'pnad_novo', tableField: 'analfabetismo', - resultField: 'illiteracy', + resultField: 'illiteracy_id', where: { relation: '=', type: 'integer', -- GitLab