-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from smartprocure/GS-8094/consistent-api
[GS-8094] feat: `step` type contract updated to use `min` and `max` instead of …
- Loading branch information
Showing
4 changed files
with
24 additions
and
24 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,6 @@ | ||
--- | ||
'contexture-elasticsearch': major | ||
'contexture-client': major | ||
--- | ||
|
||
`step` type contract updated to use `min` and `max` instead of `range` so it can be consistent with `number` type |
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
27 changes: 9 additions & 18 deletions
27
packages/provider-elasticsearch/src/example-types/filters/step.js
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 |
---|---|---|
@@ -1,40 +1,31 @@ | ||
import _ from 'lodash/fp.js' | ||
import { pickSafeNumbers } from '../../utils/futil.js' | ||
|
||
const getMinAndMax = (range) => { | ||
const min = range[0] | ||
const max = range[range.length - 1] | ||
return { min, max } | ||
} | ||
|
||
let filter = ({ field, range }) => { | ||
const { min, max } = getMinAndMax(range) | ||
return { | ||
range: { [field]: pickSafeNumbers({ gte: min, lte: max }) }, | ||
} | ||
} | ||
let filter = ({ field, min, max }) => ({ | ||
range: { [field]: pickSafeNumbers({ gte: min, lte: max }) }, | ||
}) | ||
|
||
let buildQuery = (field, range) => { | ||
let buildQuery = (field, min, max) => { | ||
return { | ||
aggs: { | ||
rangeFilter: { | ||
filter: filter({ field, range }), | ||
filter: filter({ field, min, max }), | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
let result = async (node, search) => { | ||
let { field, range } = node | ||
const result = await search(buildQuery(field, range)) | ||
let { field, min, max } = node | ||
const result = await search(buildQuery(field, min, max)) | ||
const recordsCount = result.aggregations.rangeFilter.doc_count | ||
return { recordsCount } | ||
} | ||
|
||
export default { | ||
hasValue: ({ range }) => !_.isEmpty(range), | ||
hasValue: ({ min }) => !_.isNil(min), | ||
filter, | ||
validContext: ({ range }) => !_.isEmpty(range), | ||
validContext: ({ min }) => !_.isNil(min), | ||
result, | ||
buildQuery, | ||
} |
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