-
-
Save brian-gates/22e2e2c258d51d6b6c00 to your computer and use it in GitHub Desktop.
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
/** | |
* Convert URL query params to flattened db query params | |
* e.g. | |
* filterParams('capture', { | |
* id : [ 'codex_capture_id', 'codex_second_day_capture_id' ], | |
* shot_name : [ 'CODEX_SHOT_0000065', 'DJI00056' ] | |
* }) | |
* Results in: | |
* { | |
* filter_capture__id_0 : 'codex_capture_id', | |
* filter_capture__id_1 : 'codex_second_day_capture_id', | |
* filter_capture__shot_name_0 : 'CODEX_SHOT_0000065', | |
* filter_capture__shot_name_1 : 'DJI00056' | |
* } | |
*/ | |
var filterParams = (node, filters) => | |
R | |
.toPairs(filters) | |
.reduce( | |
(params, filterPair) => | |
filterPair[1].reduce( | |
(acc, val, i) => R.assoc(`filter_${node}__${filterPair[0]}_${i}`, val, acc), | |
params | |
) | |
, | |
{} | |
) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment