refact: FilterNode has filterType not just type

This commit is contained in:
ysandler 2020-05-19 23:09:31 -05:00 committed by root
parent a195b75154
commit 62bccd234d
3 changed files with 20 additions and 24 deletions

View File

@ -45,14 +45,10 @@ class Node {
this.id = props.id this.id = props.id
this.label = props.label this.label = props.label
this.type = 'Node' this.type = 'Node'
if (props.tables) {
this.importTables(props.tables)
} else {
this.tables = []
}
this.isValid = true this.isValid = true
if (props.tables) this.importTables(props.tables)
else this.tables = []
} }
_validateTables = tablesToImport => { _validateTables = tablesToImport => {

View File

@ -13,10 +13,10 @@ class FilterNode extends Node {
else this.filterParams = {...this.filterParams, ...params} else this.filterParams = {...this.filterParams, ...params}
} }
setType = type => { setFilterType = filterType => {
const typeValidation = this._validateType(type) const typeValidation = this._validateType(filterType)
if (typeValidation.status === 'ERR') throw typeValidation if (typeValidation.status === 'ERR') throw typeValidation
else this.type = type else this.filterType = filterType
} }
export = () => { export = () => {
@ -32,25 +32,25 @@ class FilterNode extends Node {
_assignProps = props => { _assignProps = props => {
this.filterParams = props.filterParams || {} this.filterParams = props.filterParams || {}
if (props.type) this.setType(props.type) if (props.filterType) this.setFilterType(props.filterType)
} }
_createFilterMethods = () => { _createFilterMethods = () => {
const typeValidation = this._validateType(this.type) const typeValidation = this._validateType(this.filterType)
if (typeValidation.status !== 'OK') throw typeValidation if (typeValidation.status !== 'OK') throw typeValidation
let filters = [] let filters = []
for (let key in this.filterParams) { for (let key in this.filterParams) {
let filterMethod = {} let filterMethod = {}
if (this.type === filterTypes.EQUAL) if (this.filterType === filterTypes.EQUAL)
filterMethod = t => t[key] === this.filterParams[key] 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] 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] 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] 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] filterMethod = t => t[key] <= this.filterParams[key]
filters.push(filterMethod) filters.push(filterMethod)

View File

@ -33,7 +33,7 @@ const equalFilter = () => {
data: 'row', data: 'row',
contractor: 'AshBritt' contractor: 'AshBritt'
}, },
type: 'EQUAL' filterType: 'EQUAL'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@ -79,7 +79,7 @@ const addFilter = () => {
filterParams: { filterParams: {
data: 'row', data: 'row',
}, },
type: 'EQUAL' filterType: 'EQUAL'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@ -189,7 +189,7 @@ const setType = () => {
} }
try { try {
filterNode.setType('EQUAL') filterNode.setFilterType('EQUAL')
} catch (err) { } catch (err) {
console.log(err) console.log(err)
return false return false
@ -234,7 +234,7 @@ const greaterFilter = () => {
filterParams: { filterParams: {
count: 4 count: 4
}, },
type: 'GREATER' filterType: 'GREATER'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@ -287,7 +287,7 @@ const greaterEqualFilter = () => {
filterParams: { filterParams: {
count: 4 count: 4
}, },
type: 'GREATEREQUAL' filterType: 'GREATEREQUAL'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@ -338,7 +338,7 @@ const lesserFilter = () => {
filterParams: { filterParams: {
count: 4 count: 4
}, },
type: 'LESSER' filterType: 'LESSER'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)
@ -390,7 +390,7 @@ const lesserEqualFilter = () => {
filterParams: { filterParams: {
count: 4 count: 4
}, },
type: 'LESSEREQUAL' filterType: 'LESSEREQUAL'
}) })
} catch (err) { } catch (err) {
console.log(err) console.log(err)