Skip to content

Instantly share code, notes, and snippets.

@brian-gates
Created December 1, 2015 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brian-gates/22e2e2c258d51d6b6c00 to your computer and use it in GitHub Desktop.
Save brian-gates/22e2e2c258d51d6b6c00 to your computer and use it in GitHub Desktop.
/**
* 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