Skip to content

Commit

Permalink
Fixes #36 consersion of values to str or int with specific tag
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoEVCosta committed May 21, 2019
1 parent 616a98a commit c0750f0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/brapi/helpers/formatRetreivedData.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getValueFromTable(key,value,db){
var column="";
value.length==0 ? column=key : column=value
dbValue=db.dataValues[column]
if(dbValue==null || typeof dbValue == "object" ){ // this avoid getting tables in next iteration when values are tables.
if(dbValue==null || typeof dbValue == "object" ){ // this avoids getting tables in next iteration when values are tables.
return column
}
return dbValue==null ? column : dbValue
Expand Down Expand Up @@ -173,7 +173,7 @@ function goToTableFromOtherSpecialTables(key,directions,db,table,destinationTabl
function specialTables(key,directions,db,table,destinationTable){
if ( table == "ObservationUnit" ){
//with this table the path is extracted from level
return goToTableFromObservationUnits()
return goToTableFromObservationUnits(key,directions,db,table,destinationTable)
}else{
//with the other tables the path has to be discovered
return goToTableFromOtherSpecialTables(key,directions,db,table,destinationTable)
Expand Down Expand Up @@ -221,6 +221,8 @@ function processMultipleTables(directions,db,table){

function getvalueFromNextTable(key,directions,db,table){
var column="";
let parseint=false
let parsestr=false
let result=processMultipleTables(directions,db,table)
if( result != null){
db=result.db;
Expand All @@ -234,25 +236,31 @@ function getvalueFromNextTable(key,directions,db,table){
return null
}
}
if(Object.keys(directions).length==2 ){
if(Object.keys(directions).length>=2 ){
if(typeof directions._attribute == "object" || typeof directions._model == "object" ){
return processMultipleAttributes(table,directions,db)
}else{
if (directions._parse=="int") parseint=true
if (directions._parse=="str") parsestr=true
column=directions._attribute
}
}else{
column=key
}
if (parseint) return parseInt(db.dataValues[table].dataValues[column])
if (parsestr) return String(db.dataValues[table].dataValues[column])
return db.dataValues[table].dataValues[column]
}

function processSingleValueObject(key,value,db){
try{
let directions=value
//////REMOVEE!!!!!!!!!!!!!!!!!!!!!!!
let special=doSpecialTableProcessing(key,directions,db)
if( special != null){
return special
}
/////REMOVEE!!!!!!!!!!!!!!!!!!!!!!!!!
return getvalueFromNextTable(key,directions,db)
}catch(err){
debug_std("Error while processing Object values from table ["+value._table+"] - "+err);
Expand Down Expand Up @@ -307,7 +315,9 @@ function determineActionForJSONObject(key,value,db){
if(value._attribute == null)
return processMultiValueObject(key,value,db);
}
if( Object.keys(value).length>2){
if( Object.keys(value).length>2){
if(value._attribute != null && value._parse != null) console.log("THHHHHHHEEEEE BONGGGG")
if(value._attribute != null && value._parse != null) return processSingleValueObject(key,value,db);
return processMultiValueObject(key,value,db)
}
}
Expand All @@ -324,7 +334,7 @@ function determinActionForJSONinstance(key,value,db){

function determineActionForKey(key,value,db){
if (typeof value == "string" || typeof value == "number"){
return String(getValueFromTable(key,value,db))
return getValueFromTable(key,value,db)
}
if (typeof value == "object"){
return determinActionForJSONinstance(key,value,db)
Expand Down

0 comments on commit c0750f0

Please sign in to comment.