Skip to content

Commit

Permalink
Merge pull request #504 from nightscout/wip/api-params
Browse files Browse the repository at this point in the history
allow API to search things better
  • Loading branch information
jasoncalabrese committed Mar 22, 2015
2 parents f308fa2 + 4f11948 commit 8889ceb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function configure (app, wares, entries) {
es.pipeline(output, sgvdata.format( ), res);
},
json: function ( ) {
es.pipeline(output, sgvdata.lint({strict: false}), es.writeArray(function (err, out) {
es.pipeline(output, entries.map( ), es.writeArray(function (err, out) {
res.json(out);
}));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function configure (app, wares, treatments) {

// List settings available
api.get('/treatments/', function(req, res) {
treatments.list({}, function (err, profiles) {
treatments.list({find: req.params}, function (err, profiles) {
return res.json(profiles);
});
});
Expand Down
15 changes: 14 additions & 1 deletion lib/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ var TEN_MINS = 10 * 60 * 1000;
* Encapsulate persistent storage of sgv entries.
\**********/

function find_sgv_query (opts) {
if (opts && opts.find && opts.find.sgv) {
Object.keys(opts.find.sgv).forEach(function (key) {
var is_keyword = /^\$/g;
if (is_keyword.test(key)) {
opts.find.sgv[key] = parseInt(opts.find.sgv[key]);
}
});
}
return opts;
}

function storage(name, storage, pushover) {

// TODO: Code is a little redundant.
Expand All @@ -25,7 +37,8 @@ function storage(name, storage, pushover) {

// determine find options
function find ( ) {
var q = opts && opts.find ? opts.find : { };
var finder = find_sgv_query(opts);
var q = finder && finder.find ? finder.find : { };
return q;
// return this.find(q);
}
Expand Down

0 comments on commit 8889ceb

Please sign in to comment.