Skip to content

Commit

Permalink
Merge pull request #20 from nightscout/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
inventor96 authored Sep 30, 2020
2 parents 6544a40 + 1818810 commit 86b35c2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/server/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function cache (env, ctx) {
}

data.isEmpty = (datatype) => {
return data[datatype].length == 0;
return data[datatype].length < 20;
}

data.getData = (datatype) => {
Expand Down
70 changes: 45 additions & 25 deletions lib/server/devicestatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,51 @@ var find_options = require('./query');

function storage (collection, ctx) {

function create (obj, fn) {

// Normalize all dates to UTC
const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment();
obj.created_at = d.toISOString();
obj.utcOffset = d.utcOffset();

api().insertOne(obj, function(err, results) {
if (err !== null && err.message) {
console.log('Error inserting the device status object', err.message);
fn(err.message, null);
return;
}
function create (statuses, fn) {

if (!err) {
if (!Array.isArray(statuses)) { statuses = [statuses]; }

if (!obj._id) obj._id = results.insertedIds[0]._id;
const r = [];
let errorOccurred = false;

ctx.bus.emit('data-update', {
type: 'devicestatus'
, op: 'update'
, changes: ctx.ddata.processRawDataForRuntime([obj])
});
}
for (let i = 0; i < statuses.length; i++) {

fn(null, results.ops);
ctx.bus.emit('data-received');
});
const obj = statuses[i];

if (errorOccurred) return;

// Normalize all dates to UTC
const d = moment(obj.created_at).isValid() ? moment.parseZone(obj.created_at) : moment();
obj.created_at = d.toISOString();
obj.utcOffset = d.utcOffset();

api().insertOne(obj, function(err, results) {
if (err !== null && err.message) {
console.log('Error inserting the device status object', err.message);
errorOccurred = true;
fn(err.message, null);
return;
}

if (!err) {

if (!obj._id) obj._id = results.insertedIds[0]._id;
r.push(obj);

ctx.bus.emit('data-update', {
type: 'devicestatus'
, op: 'update'
, changes: ctx.ddata.processRawDataForRuntime([obj])
});

// Last object! Return results
if (i == statuses.length - 1) {
fn(null, r);
ctx.bus.emit('data-received');
}
}
});
};
}

function last (fn) {
Expand Down Expand Up @@ -109,7 +126,10 @@ function storage (collection, ctx) {
api.aggregate = require('./aggregate')({}, api);
api.indexedFields = [
'created_at'





, 'NSCLIENT_ID'
];
return api;
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout",
"version": "14.0.5",
"version": "14.0.6",
"description": "Nightscout acts as a web-based CGM (Continuous Glucose Montinor) to allow multiple caregivers to remotely view a patients glucose data in realtime.",
"license": "AGPL-3.0",
"author": "Nightscout Team",
Expand Down
2 changes: 1 addition & 1 deletion swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"info": {
"title": "Nightscout API",
"description": "Own your DData with the Nightscout API",
"version": "14.0.5",
"version": "14.0.6",
"license": {
"name": "AGPL 3",
"url": "https://www.gnu.org/licenses/agpl.txt"
Expand Down
2 changes: 1 addition & 1 deletion swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ servers:
info:
title: Nightscout API
description: Own your DData with the Nightscout API
version: 14.0.5
version: 14.0.6
license:
name: AGPL 3
url: 'https://www.gnu.org/licenses/agpl.txt'
Expand Down

0 comments on commit 86b35c2

Please sign in to comment.