refact: FilterNode has filterType not just type
This commit is contained in:
parent
988d256873
commit
6b82a167b6
@ -45,14 +45,10 @@ class Node {
|
||||
this.id = props.id
|
||||
this.label = props.label
|
||||
this.type = 'Node'
|
||||
|
||||
if (props.tables) {
|
||||
this.importTables(props.tables)
|
||||
} else {
|
||||
this.tables = []
|
||||
}
|
||||
|
||||
this.isValid = true
|
||||
|
||||
if (props.tables) this.importTables(props.tables)
|
||||
else this.tables = []
|
||||
}
|
||||
|
||||
_validateTables = tablesToImport => {
|
||||
|
@ -13,10 +13,10 @@ class FilterNode extends Node {
|
||||
else this.filterParams = {...this.filterParams, ...params}
|
||||
}
|
||||
|
||||
setType = type => {
|
||||
const typeValidation = this._validateType(type)
|
||||
setFilterType = filterType => {
|
||||
const typeValidation = this._validateType(filterType)
|
||||
if (typeValidation.status === 'ERR') throw typeValidation
|
||||
else this.type = type
|
||||
else this.filterType = filterType
|
||||
}
|
||||
|
||||
export = () => {
|
||||
@ -32,25 +32,25 @@ class FilterNode extends Node {
|
||||
|
||||
_assignProps = props => {
|
||||
this.filterParams = props.filterParams || {}
|
||||
if (props.type) this.setType(props.type)
|
||||
if (props.filterType) this.setFilterType(props.filterType)
|
||||
}
|
||||
|
||||
_createFilterMethods = () => {
|
||||
const typeValidation = this._validateType(this.type)
|
||||
const typeValidation = this._validateType(this.filterType)
|
||||
if (typeValidation.status !== 'OK') throw typeValidation
|
||||
|
||||
let filters = []
|
||||
for (let key in this.filterParams) {
|
||||
let filterMethod = {}
|
||||
if (this.type === filterTypes.EQUAL)
|
||||
if (this.filterType === filterTypes.EQUAL)
|
||||
filterMethod = t => t[key] === this.filterParams[key]
|
||||
else if (this.type === filterTypes.GREATER)
|
||||
else if (this.filterType === filterTypes.GREATER)
|
||||
filterMethod = t => t[key] > this.filterParams[key]
|
||||
else if (this.type === filterTypes.GREATEREQUAL)
|
||||
else if (this.filterType === filterTypes.GREATEREQUAL)
|
||||
filterMethod = t => t[key] >= this.filterParams[key]
|
||||
else if (this.type === filterTypes.LESSER)
|
||||
else if (this.filterType === filterTypes.LESSER)
|
||||
filterMethod = t => t[key] < this.filterParams[key]
|
||||
else if (this.type === filterTypes.LESSEREQUAL)
|
||||
else if (this.filterType === filterTypes.LESSEREQUAL)
|
||||
filterMethod = t => t[key] <= this.filterParams[key]
|
||||
|
||||
filters.push(filterMethod)
|
||||
|
@ -33,7 +33,7 @@ const equalFilter = () => {
|
||||
data: 'row',
|
||||
contractor: 'AshBritt'
|
||||
},
|
||||
type: 'EQUAL'
|
||||
filterType: 'EQUAL'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@ -79,7 +79,7 @@ const addFilter = () => {
|
||||
filterParams: {
|
||||
data: 'row',
|
||||
},
|
||||
type: 'EQUAL'
|
||||
filterType: 'EQUAL'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@ -189,7 +189,7 @@ const setType = () => {
|
||||
}
|
||||
|
||||
try {
|
||||
filterNode.setType('EQUAL')
|
||||
filterNode.setFilterType('EQUAL')
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return false
|
||||
@ -234,7 +234,7 @@ const greaterFilter = () => {
|
||||
filterParams: {
|
||||
count: 4
|
||||
},
|
||||
type: 'GREATER'
|
||||
filterType: 'GREATER'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@ -287,7 +287,7 @@ const greaterEqualFilter = () => {
|
||||
filterParams: {
|
||||
count: 4
|
||||
},
|
||||
type: 'GREATEREQUAL'
|
||||
filterType: 'GREATEREQUAL'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@ -338,7 +338,7 @@ const lesserFilter = () => {
|
||||
filterParams: {
|
||||
count: 4
|
||||
},
|
||||
type: 'LESSER'
|
||||
filterType: 'LESSER'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
@ -390,7 +390,7 @@ const lesserEqualFilter = () => {
|
||||
filterParams: {
|
||||
count: 4
|
||||
},
|
||||
type: 'LESSEREQUAL'
|
||||
filterType: 'LESSEREQUAL'
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user