32 lines
793 B
TypeScript
32 lines
793 B
TypeScript
|
type BaseFilter = {
|
||
|
createVars: () => { [key: string]: any };
|
||
|
};
|
||
|
|
||
|
function createBaseFilter(key: string, content: any): BaseFilter {
|
||
|
return {
|
||
|
createVars: () => ({ [key]: content }),
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function createAndFilter(filters: Array<BaseFilter>): BaseFilter {
|
||
|
const filterVars = filters.map((filter) => filter.createVars());
|
||
|
return createBaseFilter("andFilters", { filters: filterVars });
|
||
|
}
|
||
|
|
||
|
export function createCategoryFilter(
|
||
|
feature: string,
|
||
|
value: string,
|
||
|
): BaseFilter {
|
||
|
const content = { [feature]: { value } };
|
||
|
return createBaseFilter(feature, content);
|
||
|
}
|
||
|
|
||
|
export function createRangeFilter(
|
||
|
feature: string,
|
||
|
greaterThanEqualTo: number,
|
||
|
lessThan: number,
|
||
|
): BaseFilter {
|
||
|
const content = { greaterThanEqualTo, lessThan };
|
||
|
return createBaseFilter(feature, content);
|
||
|
}
|