Commit 10f45d72 authored by Pietro Cavassin's avatar Pietro Cavassin
Browse files

Merge branch 'issue792_Pietro' into 'dev'

update booleanVariable to convert pattern

See merge request !318
parents 9db24d26 d98f9f19
......@@ -20,8 +20,12 @@ along with simcaq-node. If not, see <https://www.gnu.org/licenses/>.
module.exports = function booleanVariable(id) {
switch(id){
case 1:
return 'Sim';
case true:
return 'Sim';
case 0:
return 'Não';
case false:
return 'Não';
default:
......
......@@ -6,10 +6,6 @@ const id2str = require(`${libs}/middlewares/id2str`);
const _ = require('lodash');
const nullFields = [
"Não classificado",
"Não classificada"
]
function parseWhereValue(type, value, relation) {
if (value == null)
......@@ -33,26 +29,6 @@ function parseWhereValue(type, value, relation) {
}
}
function getConvertName(whereField){ // TODO: mudar para regex
// Pega nome no formato "exemplo_de_nome" e transforma em "exemploDeNome"
for (var i = 1; i < whereField.length; ++i){
if (whereField[i] == "_" && i < whereField.length-1)
whereField = whereField.slice(0,i) + whereField[i+1].toUpperCase() + whereField.slice(i+2, whereField.length);
}
return whereField;
}
function isNull(curFilter, value){
// TODO: Remove this function
if (value == null)
return true;
let convertName = getConvertName(curFilter)
if (id2str[convertName] !== undefined){
return nullFields.indexOf(id2str[convertName](value)) > -1
}
return false;
}
class ReqQueryFields {
constructor(fields = {}, fieldValues = {}) {
// Exemplo de requisição: `/api/v1/enrollments?dims=state,region,location`
......@@ -333,10 +309,8 @@ class ReqQueryFields {
for(let i = 0; i < whereValue.length; ++i) {
let curRelation = value.where.relation;
let curValue = parseWhereValue(value.where.type, whereValue[i],value.where.relation)
if (isNull(k, curValue)) {
curValue = null;
if (curValue === null)
curRelation = "is";
}
whereString += whereField + ' ' + curRelation + lower;
arrayWhereValues.push(curValue);
......@@ -350,10 +324,8 @@ class ReqQueryFields {
let curValue = parseWhereValue(value.where.type, whereValue, value.where.relation)
let curRelation = value.where.relation;
if (isNull(k, curValue) ) {
curValue = null;
if (curValue === null )
curRelation = "is";
}
sql.where(whereField + ' ' + curRelation + lower, curValue);
}
......
......@@ -395,7 +395,7 @@ rqf.addField({
resultField: 'substitute_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'docente_substituto'
}
}).addValue({
......@@ -405,7 +405,7 @@ rqf.addField({
resultField: 'visitor_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'docente_visitante'
}
}).addValue({
......@@ -415,7 +415,7 @@ rqf.addField({
resultField: 'ead_teacher_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'ministra_aula_ead'
}
}).addValue({
......@@ -425,7 +425,7 @@ rqf.addField({
resultField: 'graduation_presential_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'atua_atividade_graduacao_presencial'
}
}).addValue({
......@@ -435,7 +435,7 @@ rqf.addField({
resultField: 'postgraduate_ead_teacher_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'atua_atividade_posgraduacao_distancia'
}
}).addValue({
......@@ -445,7 +445,7 @@ rqf.addField({
resultField: 'postgraduate_presential_teacher_id',
where: {
relation: '=',
type: 'integer',
type: 'boolean',
field: 'atua_atividade_posgraduacao_presencial'
}
}).addValue({
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment