-
Notifications
You must be signed in to change notification settings - Fork 29
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 #80 from storyblok/task/int-1075-starts-with-and-f…
…ilter-query feat(int-1075): Sync only certain pages from one space to the other
- Loading branch information
Showing
5 changed files
with
126 additions
and
62 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
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
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,29 @@ | ||
const buildFilterQuery = (keys, operations, values) => { | ||
const operators = ['is', 'in', 'not_in', 'like', 'not_like', 'any_in_array', 'all_in_array', 'gt_date', 'lt_date', 'gt_int', 'lt_int', 'gt_float', 'lt_float'] | ||
|
||
if (!keys || !operations || !values) { | ||
throw new Error('Filter options are required: --keys; --operations; --values') | ||
} | ||
const _keys = keys.split(',') | ||
const _operations = operations.split(',') | ||
const _values = values.split(',') | ||
|
||
if (_keys.length !== _operations.length || _keys.length !== _values.length) { | ||
throw new Error('The number of keys, operations and values must be the same') | ||
} | ||
|
||
const invalidOperators = _operations.filter((o) => !operators.includes(o)) | ||
|
||
if (invalidOperators.length) { | ||
throw new Error('Invalid operator(s) applied for filter: ' + invalidOperators.join(' ')) | ||
} | ||
|
||
const filterQuery = {} | ||
_keys.forEach((key, index) => { | ||
filterQuery[key] = { [_operations[index]]: _values[index] } | ||
}) | ||
|
||
return filterQuery | ||
} | ||
|
||
export default buildFilterQuery |
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