Skip to content
Snippets Groups Projects
Commit 43ecf86f authored by Pietro Cavassin's avatar Pietro Cavassin
Browse files

only relation like adds '%' to value

parent f24218f1
No related branches found
No related tags found
2 merge requests!309Merge new updates into master,!279Homologa
Pipeline #27666 failed
...@@ -11,10 +11,11 @@ const nullFields = [ ...@@ -11,10 +11,11 @@ const nullFields = [
"Não classificada" "Não classificada"
] ]
function parseWhereValue(type, value) { function parseWhereValue(type, value, relation) {
if(type === 'integer') return parseInt(value, 10); if(type === 'integer') return parseInt(value, 10);
if(type === 'double') return parseFloat(value); if(type === 'double') return parseFloat(value);
if(type === 'string') return '%'+value+'%'; if(type === 'string' && relation === 'LIKE') return '%'+value+'%';
if(type === 'string') return value;
if(type === 'boolean') { if(type === 'boolean') {
if(value === null || typeof value === 'boolean') { if(value === null || typeof value === 'boolean') {
return value; return value;
...@@ -306,14 +307,14 @@ class ReqQueryFields { ...@@ -306,14 +307,14 @@ class ReqQueryFields {
let whereString = '('; let whereString = '(';
for(let i = 0; i < whereValue.length; ++i) { for(let i = 0; i < whereValue.length; ++i) {
whereString += whereField; whereString += whereField;
whereValues.push(parseWhereValue(value.where.type, whereValue[i])); whereValues.push(parseWhereValue(value.where.type, whereValue[i], value.where.relation));
if(i < whereValue.length-1) { if(i < whereValue.length-1) {
whereString += ' OR '; whereString += ' OR ';
} }
} }
whereString += ')'; whereString += ')';
} else { } else {
whereValues.push(parseWhereValue(value.where.type, whereValue)); whereValues.push(parseWhereValue(value.where.type, whereValue, value.where.relation));
} }
}); });
...@@ -326,7 +327,7 @@ class ReqQueryFields { ...@@ -326,7 +327,7 @@ class ReqQueryFields {
let arrayWhereValues = []; let arrayWhereValues = [];
for(let i = 0; i < whereValue.length; ++i) { for(let i = 0; i < whereValue.length; ++i) {
let curRelation = value.where.relation; let curRelation = value.where.relation;
let curValue = parseWhereValue(value.where.type, whereValue[i]) let curValue = parseWhereValue(value.where.type, whereValue[i],value.where.relation)
if (isNull(k, curValue) ) { if (isNull(k, curValue) ) {
curValue = null; curValue = null;
curRelation = "is"; curRelation = "is";
...@@ -341,7 +342,7 @@ class ReqQueryFields { ...@@ -341,7 +342,7 @@ class ReqQueryFields {
whereString += ')'; whereString += ')';
sql.where(whereString, ...arrayWhereValues); sql.where(whereString, ...arrayWhereValues);
} else { } else {
let curValue = parseWhereValue(value.where.type, whereValue) let curValue = parseWhereValue(value.where.type, whereValue, value.where.relation)
let curRelation = value.where.relation; let curRelation = value.where.relation;
if (isNull(k, curValue) ) { if (isNull(k, curValue) ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment