-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: product data object facets (#28)
* feat: product data object facets * add last facets, clean up tests * add missing exports Co-authored-by: Martin Zanoni <[email protected]>
- Loading branch information
Showing
8 changed files
with
396 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { DoubleRange, DataValueBase, ObjectValueMinByCondition, ObjectValueMaxByCondition, ObjectValueContainsCondition, ObjectValueEqualsCondition, ObjectValueGreaterThanCondition, ObjectValueLessThanCondition, ObjectValueInRangeCondition, ObjectValueCondition } from '..'; | ||
|
||
export type DataObjectFilterConditions = | ||
| ObjectValueContainsCondition | ||
| ObjectValueEqualsCondition | ||
| ObjectValueGreaterThanCondition | ||
| ObjectValueInRangeCondition | ||
| ObjectValueLessThanCondition | ||
| ObjectValueMaxByCondition | ||
| ObjectValueMinByCondition; | ||
|
||
export class DataObjectFilterConditionBuilder { | ||
conditions: DataObjectFilterConditions[] = []; | ||
|
||
public addContainsCondition<T>(key: string, value: DataValueBase<T>, mode: 'All' | 'Any' = 'All', objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueContainsCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueContainsCondition, Relewise.Client', | ||
key: key, | ||
value: value, | ||
objectPath: objectPath, | ||
mode: mode, | ||
negated: negated, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addEqualsCondition<T>(key: string, value: DataValueBase<T>, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueEqualsCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueEqualsCondition, Relewise.Client', | ||
value: value, | ||
objectPath: objectPath, | ||
negated: negated, | ||
key: key, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addInRangeCondition(key: string, range: DoubleRange, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueInRangeCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueInRangeCondition, Relewise.Client', | ||
range: range, | ||
key: key, | ||
objectPath: objectPath, | ||
negated: negated, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addGreaterThanCondition(key: string, value: number, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueGreaterThanCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueGreaterThanCondition, Relewise.Client', | ||
value: value, | ||
negated: negated, | ||
key: key, | ||
objectPath: objectPath, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addLessThanCondition(key: string, value: number, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueLessThanCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueLessThanCondition, Relewise.Client', | ||
value: value, | ||
negated: negated, | ||
key: key, | ||
objectPath: objectPath, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addMinByCondition(key: string, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueMinByCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueMinByCondition, Relewise.Client', | ||
negated: negated, | ||
key: key, | ||
objectPath: objectPath, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public addMaxByCondition(key: string, objectPath?: string[], negated: boolean = false): this { | ||
const condition: ObjectValueMaxByCondition = { | ||
$type: 'Relewise.Client.Requests.Filters.DataObjects.Conditions.ObjectValueMaxByCondition, Relewise.Client', | ||
negated: negated, | ||
key: key, | ||
objectPath: objectPath, | ||
}; | ||
this.conditions.push(condition); | ||
|
||
return this; | ||
} | ||
|
||
public build(): DataObjectFilterConditions[] | null { | ||
return this.conditions.length === 0 | ||
? null | ||
: this.conditions | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { DataObjectBooleanValueFacet, DataObjectDoubleRangeFacet, DataObjectDoubleRangesFacet, DataObjectDoubleValueFacet, DataObjectStringValueFacet, FacetSettings } from '../../models/data-contracts'; | ||
|
||
|
||
export class DataObjectFacetBuilder { | ||
private facets: ( | ||
DataObjectDoubleRangeFacet | | ||
DataObjectDoubleRangesFacet | | ||
DataObjectStringValueFacet | | ||
DataObjectBooleanValueFacet | | ||
DataObjectDoubleValueFacet)[] = []; | ||
|
||
public addStringFacet( | ||
key: string, | ||
selectedValues: string[] | null = null, | ||
collectionFilterType?: 'Or' | 'And', | ||
facetSettings?: FacetSettings): this { | ||
|
||
const facet: DataObjectStringValueFacet = { | ||
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.DataObjectStringValueFacet, Relewise.Client', | ||
field: 'Data', | ||
key: key, | ||
selected: selectedValues, | ||
collectionFilterType: collectionFilterType, | ||
settings: facetSettings, | ||
}; | ||
this.facets.push(facet); | ||
|
||
return this; | ||
} | ||
|
||
public addBooleanFacet( | ||
key: string, | ||
selectedValues: boolean[] | null = null, | ||
collectionFilterType?: 'Or' | 'And', | ||
facetSettings?: FacetSettings): this { | ||
|
||
const facet: DataObjectBooleanValueFacet = { | ||
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.DataObjectBooleanValueFacet, Relewise.Client', | ||
field: 'Data', | ||
key: key, | ||
selected: selectedValues, | ||
collectionFilterType: collectionFilterType, | ||
settings: facetSettings, | ||
}; | ||
this.facets.push(facet); | ||
|
||
return this; | ||
} | ||
|
||
public addNumberFacet( | ||
key: string, | ||
selectedValues: number[] | null = null, | ||
collectionFilterType?: 'Or' | 'And', | ||
facetSettings?: FacetSettings): this { | ||
|
||
const facet: DataObjectDoubleValueFacet = { | ||
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.DataObjectDoubleValueFacet, Relewise.Client', | ||
field: 'Data', | ||
key: key, | ||
selected: selectedValues, | ||
collectionFilterType: collectionFilterType, | ||
settings: facetSettings, | ||
}; | ||
this.facets.push(facet); | ||
|
||
return this; | ||
} | ||
|
||
public addNumberRangeFacet( | ||
key: string, | ||
lowerBound?: number | null, | ||
upperBound?: number | null, | ||
facetSettings?: FacetSettings): this { | ||
|
||
const facet: DataObjectDoubleRangeFacet = { | ||
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.DataObjectDoubleRangeFacet, Relewise.Client', | ||
field: 'Data', | ||
key: key, | ||
selected: { | ||
lowerBoundInclusive: lowerBound, | ||
upperBoundInclusive: upperBound, | ||
}, | ||
settings: facetSettings, | ||
}; | ||
this.facets.push(facet); | ||
|
||
return this; | ||
} | ||
|
||
public addNumberRangesFacet( | ||
key: string, | ||
predefinedRanges?: { | ||
lowerBound?: number, | ||
upperBound?: number | ||
}[] | null, | ||
expandedRangeSize?: number | null, | ||
selectedValues: { | ||
lowerBound?: number, | ||
upperBound?: number | ||
}[] | null = null, | ||
facetSettings?: FacetSettings): this { | ||
|
||
const facet: DataObjectDoubleRangesFacet = { | ||
$type: 'Relewise.Client.DataTypes.Search.Facets.Queries.DataObjectDoubleRangesFacet, Relewise.Client', | ||
field: 'Data', | ||
key: key, | ||
settings: facetSettings, | ||
predefinedRanges: predefinedRanges?.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })), | ||
expandedRangeSize: expandedRangeSize, | ||
selected: selectedValues?.map(x => ({ lowerBoundInclusive: x.lowerBound, upperBoundExclusive: x.upperBound })), | ||
}; | ||
this.facets.push(facet); | ||
|
||
return this; | ||
} | ||
|
||
build() { | ||
return this.facets.length === 0 | ||
? null | ||
: this.facets; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.