mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
allow API to search things better
This allows a query such as this to search for events of hypoglycemia for
example:
curl -g localhost:3434 \
/api/v1/entries \
'?find[sgv][$lte]=70&find[sgv][$gte]=20&count=1000
It's possible to construct most mongo queries by url encoding the query string.
In this instance, mongo performs poorly when searching for lte/gte for strings.
In order for ranged queries to perform properly, the query parameters must be
set to integer type. There is a quick and ugly helper to ensure that some sgv
queries will be respected as integer searches.
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
+14
-1
@@ -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.
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user