jesuspc / node_club-dictionaries

A dictionaries microservices for Workshare's Node club
1 stars 0 forks source link

filters for index endpoint #16

Closed JamesSwandale closed 8 years ago

jesuspc commented 8 years ago

The whole functionality of folders is still not covered I believe. The idea is to be able to filter by an arbitrary key in the dictionary (which could be a json object itself). By now only filtering by name is supported. Also, a 'querified' object is expected for the filters key. That means that a filter such as {'filters': {'some-filter': 'some-value'}} would be encoded as %5Bdealroom-fe-timeline%5D=some_value, being therefore the query something like:

https://dev4.workshare.com/dictionaries/api/v1.0/USERS_OR_ACCOUNTS/UUID/dictionaries.json?filters%5Bsome-filter%5D=some-value

You can use the default 'querystring' library in order to encode/decode those inputs if needed:

var querystring = require('querystring');

var stringified = querystring.stringify({'filters[some-filter]': 'some-value'});
stringified; //=> 'filters%5Bsome-filter%5D=some-value'
var decoded = querystring.parse(stringified);
decoded; //=> { 'filters[some-filter]': 'some-value' }

Alternatively you can install the qs module (probably you'll need a version '~5.0' otherwise node is going to complain about the version), which may make your life better since it can decode in a proper javascript object.

// After npm install
var qs = require('qs');
Qs.parse('filters%5Bsome-filter%5D=some-value'); //=> {'filters': {'some-filter': 'some-value'}}