Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundled features for 0.11 that need to be tested and approved before being merged #4169

Merged
merged 146 commits into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
c69357e
Merge pull request #1 from nightscout/dev
lixgbg Mar 10, 2018
a89487a
Fixed raw bg calculations to use noise level to determine filters vs.…
Feb 14, 2018
5643aa0
Changed test to use the updated rawbg calculation values.
Feb 14, 2018
fafd01a
Merge pull request #8 from nightscout/dev
lixgbg May 28, 2018
0569283
First test deploy
May 29, 2018
166af84
Test
May 29, 2018
d166748
Loopalyzer works
May 29, 2018
51ac316
Works ok (minor bug in predictions)
May 30, 2018
a09c434
v0.5 works well
May 31, 2018
9f663d0
Merge pull request #9 from lixgbg/wip/report-loopalyzer-dev
lixgbg May 31, 2018
7c92b2e
Fixed so Predictions legend is not shown unless Predictions are shown
May 31, 2018
19f2dcc
Fixed hang if no COB/IOB
Jun 1, 2018
b7dc589
Changed to Nightscouts default way of reading IOB/COBs
Jun 2, 2018
3fe8e8b
Fixed new COB compute (refactor, simpler)
Jun 3, 2018
6eaa021
Fixed IOB calculations as well
Jun 3, 2018
c87c24c
Refactored getBasals and getTempBasals
Jun 3, 2018
ea9a9cc
Refactored the interpolation back into the IOB/COB functions
Jun 3, 2018
7ceeb4d
Added OpenAPS (and AndroidAPS?) to Predictions
Jun 3, 2018
db8039c
Added version info to log output
Jun 3, 2018
86c9693
Merge pull request #11 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 3, 2018
aad095e
Added one week time limit to limit CPU
Jun 3, 2018
8f4d6ab
Merge pull request #12 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 3, 2018
c588796
Fixed bug calculation IOB total when not using deviceStatus
Jun 4, 2018
8a0d09d
Added info text and improve finding NaNs
Jun 4, 2018
b32cd0e
Merge pull request #13 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 4, 2018
f10ecbe
Logging carb and insulin treatments
Jun 4, 2018
21e7690
Merge pull request #14 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 4, 2018
8783437
Added fill-in using carb and insulin treatments to avoid gaps in graphs
Jun 6, 2018
229f368
Merge pull request #15 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 6, 2018
be6b2af
Optimized the interpolation of IOB and COB
Jun 10, 2018
a69775f
Merge pull request #16 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
2934bac
Removed extensive logging, spell check, version number update
Jun 10, 2018
2ad755f
Merge pull request #17 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
23d3f83
Ready for Nightscout submission
Jun 10, 2018
d8b1da1
Merge pull request #18 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
1e1d1a2
Cleaned up according to codacy-bot
Jun 10, 2018
40faa55
Merge pull request #19 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
d581e59
More cleanup according to codacy-bot
Jun 10, 2018
0d550f7
Merge pull request #20 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
5f57aea
Final cleanup for codacy-bot
Jun 10, 2018
9a0e409
Merge pull request #21 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
abae64a
Really final cleanup for codacy-bot
Jun 10, 2018
8084103
Merge pull request #22 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 10, 2018
57f67d2
After npm update
Jun 25, 2018
9f91e04
Merge pull request #24 from lixgbg/wip/report-loopalyzer-dev
lixgbg Jun 25, 2018
dd1a3ea
remove python and python-software-properties from setup.sh
PieterGit Jul 10, 2018
7bafa94
Made new functionality an option.
Aug 17, 2018
6f633b8
Added new rawbg extended setting.
Aug 17, 2018
46c426d
Check if sbx argument was provided.
Aug 17, 2018
0aa594f
extended settings boolean auto detected
Aug 17, 2018
da31b3b
rawbg needs sbx with extended settings.
Aug 17, 2018
f246c85
rawbg needs withextendedsettings in renderer.
Aug 17, 2018
99658b8
Add preference to choose between plotting filtered or unfiltered raw …
Aug 18, 2018
b4f1662
Fix syntax error.
Aug 18, 2018
69b098f
Initial weektoweek
Nov 29, 2018
021a921
More updates for weektoweek
Dec 1, 2018
af8a1c6
Add weektoweek report to index
Dec 1, 2018
4877a9c
Fix syntax error
Dec 1, 2018
5c65790
Fix syntax error
Dec 1, 2018
f70f0ed
Fix spelling for localeData
Dec 1, 2018
8e573b7
Fix initialization of weekstoshow array
Dec 1, 2018
e41f8f8
Initialize new week
Dec 1, 2018
f6bfec0
Fix call to prepareHtml
Dec 1, 2018
9713783
Make new sgv array for each week
Dec 2, 2018
d157313
Fix reference into datastorage array
Dec 2, 2018
88cd9aa
Increment currDay as required
Dec 2, 2018
670f172
Add weektoweek debug logs
Dec 2, 2018
f74eeaf
Fix syntax error
Dec 2, 2018
577726b
Fixed index error
Dec 2, 2018
72bc14c
Handle sort order differences
Dec 2, 2018
6605535
Sort week before prepareHtml
Dec 2, 2018
75c05f9
Fix syntax error
Dec 2, 2018
b38bea3
Test fix for week partition
Dec 3, 2018
c12ec3b
Fix first day of week getting squashed
Dec 3, 2018
b6fd5f7
Fix it for real this time
Dec 3, 2018
3c20084
Don't move to next week if current week is empty
Dec 4, 2018
34990da
Fix syntax error
Dec 4, 2018
14fa9ef
Color by day and week report specific size and scale
Dec 5, 2018
3af52f9
Comment out some debug
Dec 5, 2018
49bcfcf
style format update
Dec 5, 2018
6825eda
Use from and to dates to set week span for week2week
Dec 5, 2018
594bae9
Fix newest on top start point
Dec 5, 2018
9ecdb89
Fix newest on top
Dec 5, 2018
06d7e4e
Don't render week to week if not selected
Dec 5, 2018
d31099d
Add unit test for weektoweek report
Dec 6, 2018
cd6fb2e
Remove weektoweek logging code
Dec 6, 2018
759dd40
Add clean treatments admin tool.
Nov 21, 2018
cd459fa
Fix clean treatments status html id name
Nov 21, 2018
b429eef
Return status to treatments delete by query
Nov 21, 2018
9123de4
Add clean entries db admin tool
Nov 21, 2018
15cbfea
Correct delete query fields for entries db
Nov 21, 2018
ff04394
Make devicestatus delete consistent with entries
Nov 21, 2018
769b66a
cleanup devicestatus delete
Nov 21, 2018
44baf2e
Add isId to api/devicestatus
Nov 21, 2018
c6e2056
Set query options correctly for devicestatus
Nov 21, 2018
098f372
Use dateString for devicestatus date field
Nov 21, 2018
4f10e03
Fix devicestatus default date field
Nov 21, 2018
71efc5e
Fix devicestatus delete query handling
Nov 21, 2018
41d9d8a
No 'model' concept for devicestatus
Nov 21, 2018
d1b5c56
initialize query find by id correctly for devicestatus delete
Nov 21, 2018
af3e01a
Match devicestatus api indention
Nov 21, 2018
69b73df
Make treatments delete match devicestatus
Nov 21, 2018
ada17c8
Remove old treatments id api path
Nov 21, 2018
50952de
Add entries support for delete query
Nov 21, 2018
b448906
Remove unused function.
Nov 22, 2018
7a01c40
Removed unused function.
Nov 22, 2018
1734ec1
Add API updates for new delete options.
Dec 2, 2018
440807e
Reload data when entries or treatments are deleted
Dec 7, 2018
aa90fd5
Fix week 2 week report when not all weekdays are selected
Dec 8, 2018
6aef8ed
Fix weekNum calculation
Dec 8, 2018
bef3b69
Make week2week more resilient to date selections
Dec 8, 2018
30feb86
Fix codacy findings
Dec 8, 2018
ed97169
Remove more unused variables
Dec 8, 2018
9b59845
Add new strings to language.js
Dec 10, 2018
8136633
Prevent deleting entries or treatments more recent than 2 days ago
Dec 10, 2018
d9527d3
Add unit test for removing old devicestatus records
Dec 10, 2018
a34167a
Fix codacy finding
Dec 10, 2018
83bd1a7
Add unit test for cleantreatmentsdb.js
Dec 10, 2018
d3368e5
Add unit test for cleanentriesdb.js
Dec 10, 2018
70e50bf
Update Makefile
sulkaharo Dec 12, 2018
19e7bc3
Add insert, query, delete test for treatments api
Dec 15, 2018
44d9c54
Add insert, query, delete test for entries api
Dec 16, 2018
8921e3a
Add insert, query, delete test for devicestatus api
Dec 16, 2018
201aac6
Add support for Node 10. Upgrade to node 8.14.x . Don't start on olde…
PieterGit Dec 24, 2018
89bb3c2
allow node ^10.4.2 || ^8.14.1 || ~8.11.1
PieterGit Dec 24, 2018
87c101a
fix version typo and add missing parts of PR
Dec 26, 2018
3355566
Merge branch '201812_node10' of https://github.com/PieterGit/cgm-remo…
PieterGit Dec 31, 2018
f5df521
Merge branch 'weektoweek-report' of https://github.com/jpcunningh/cgm…
PieterGit Dec 31, 2018
e195fcb
Merge branch 'entries-and-treatments-clean-db' of https://github.com/…
PieterGit Dec 31, 2018
ddbbfe2
Merge branch 'wip/fix-rawbg-calculations' of https://github.com/jpcun…
PieterGit Dec 31, 2018
89ce188
PR with several PR's that needs testing
PieterGit Dec 31, 2018
bbb5ca9
Merge branch '201807_python' of https://github.com/PieterGit/cgm-remo…
PieterGit Dec 31, 2018
be512a0
Upgrade to Node 10 for Azure. Upgrade to version Node 8.15.0 for Node…
PieterGit Dec 31, 2018
6a792f7
Merge branch '201812_node10' of https://github.com/PieterGit/cgm-remo…
PieterGit Dec 31, 2018
f61fb94
update code comments on Node versions
PieterGit Jan 1, 2019
e88a417
Merge branch 'api-insert-delete-test' of https://github.com/jpcunning…
PieterGit Jan 1, 2019
5679266
Updated rawbg settings to use a single setting tri-state variable.
Jan 1, 2019
e77e3d8
upgrade share2nightscout-bridge to ~0.2.0-dev-20190102
PieterGit Jan 2, 2019
6a7ffa5
update to released version of share2nightscout-bridge and update webp…
PieterGit Jan 4, 2019
896d5e0
add jsdom pinned to 11.11.0 (required for benv unit tests)
PieterGit Jan 4, 2019
8f29632
Make weektoweek use SCALE_Y system setting correctly
Jan 5, 2019
716fd76
Make default scale y initialize correctly
Jan 5, 2019
a2a9248
Cleanup code for initializing weektoweek scale
Jan 5, 2019
2fded60
Merge branch 'weektoweek-report' of https://github.com/jpcunningh/cgm…
PieterGit Jan 5, 2019
9b711de
Merge branch '201901_share2nightscout' of https://github.com/PieterGi…
PieterGit Jan 5, 2019
3bd73d7
Merge branch 'wip/fix-rawbg-calculations' of https://github.com/jpcun…
PieterGit Jan 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.12.x
8.x
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ If you plan to use Nightscout, we recommend using [Heroku](http://openaps.readth

Minimum browser requirements for viewing the site:

- iOS 9
- Android 4
- Chrome 42
- Safari 9 (El Capitan)
- Firefox 34
- Chrome 68
- Edge 15
- Firefox 61
- Internet Explorer: not supported
- Opera: not supported
- iOS 9
- Safari 11
- Opera: 54

Windows installation software requirements:

- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.12.0 or later). Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`)
- [Node.js](http://nodejs.org/) Latest Node 8 LTS (Node 8.15.0 or later) or Node 10 LTS (Node 10.15.0 or later; Node 10.14.1 works for Azure). Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or use `setup.sh`)
- [MongoDB](https://www.mongodb.com/download-center?jmp=nav#community) 3.x or later. MongoDB 2.4 is only supported for Raspberry Pi.

As a non-root user clone this repo then install dependencies into the root of the project:
Expand All @@ -140,16 +140,15 @@ As a non-root user clone this repo then install dependencies into the root of th
$ npm install
```

Installation notes for Microsoft Azure, Windows and Node 10:
Installation notes for Microsoft Azure, Windows:

- If deploying the software to Microsoft Azure, you must set ** in the app settings for *WEBSITE_NODE_DEFAULT_VERSION* and *SCM_COMMAND_IDLE_TIMEOUT* **before** you deploy the latest Nightscout or the site deployment will likely fail. Other hosting environments do not require this setting. Please use:
```
WEBSITE_NODE_DEFAULT_VERSION=8.11.1
WEBSITE_NODE_DEFAULT_VERSION=10.14.1
SCM_COMMAND_IDLE_TIMEOUT=300
```
- See [install MongoDB, Node.js, and Nightscouton a single Windows system](https://github.com/jaylagorio/Nightscout-on-Windows-Server). if you want to host your Nightscout outside of the cloud. Although the instructions are intended for Windows Server the procedure is compatible with client versions of Windows such as Windows 7 and Windows 10.
- If you deploy to Windows and want to develop or test you need to install [Cygwin](https://www.cygwin.com/) (use [setup-x86_64.exe](https://www.cygwin.com/setup-x86_64.exe) and make sure to install `build-essential` package. Test your configuration by executing `make` and check if all tests are ok.
- There may be some issues with Node 10.6.0 or later with Nightscout. Node 10 support will be in the 0.11 release. Please don't use Nightscout with (Node 9 or) Node 10 at this moment.

# Usage

Expand Down Expand Up @@ -360,7 +359,11 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs.htm
An option plugin to enable adding foods from database in Bolus Wizard and enable .

##### `rawbg` (Raw BG)
Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels.
Calculates BG using sensor and calibration records from and displays an alternate BG values and noise levels. Defaults that can be adjusted with [extended setting](#extended-settings)
* `DISPLAY` (`unsmoothed`) - Allows the user to control which algorithm is used to calculate the displayed raw BG values using the most recent calibration record.
* `unfiltered` - Raw BG is calculated by applying the calibration to the glucose record's unfiltered value.
* `filtered` - Raw BG is calculated by applying the calibration to the glucose record's filtered value. The glucose record's filtered values are generally produced by the CGM by a running average of the unfiltered values to produce a smoothed value when the sensor noise is high.
* `unsmoothed` - Raw BG is calculated by first finding the ratio of the calculated filtered value (the same value calculated by the `filtered` setting) to the reported glucose value. The displayed raw BG value is calculated by dividing the calculated unfiltered value (the same value calculated by the `unfiltered` setting) by the ratio. The effect is to exagerate changes in trend direction so the trend changes are more noticeable to the user. This is the legacy raw BG calculation algorithm.

##### `iob` (Insulin-on-Board)
Adds the IOB pill visualization in the client and calculates values that used by other plugins. Uses treatments with insulin doses and the `dia` and `sens` fields from the [treatment profile](#treatment-profile).
Expand Down
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ function create(env, ctx) {
// serve the static content
app.use(staticFiles);

var swaggerFiles = express.static(env.swagger_files, {
const swaggerUiAssetPath = require("swagger-ui-dist").getAbsoluteFSPath();
var swaggerFiles = express.static(swaggerUiAssetPath, {
maxAge: maxAge
});

Expand Down
17 changes: 0 additions & 17 deletions bundle/index.js

This file was deleted.

1 change: 0 additions & 1 deletion env.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function config ( ) {
env.HOSTNAME = readENV('HOSTNAME', null);
env.IMPORT_CONFIG = readENV('IMPORT_CONFIG', null);
env.static_files = readENV('NIGHTSCOUT_STATIC_FILES', __dirname + '/static/');
env.swagger_files = readENV('NIGHTSCOUT_SWAGGER_FILES', __dirname + '/node_modules/swagger-ui-dist/');
env.debug = {
minify: readENVTruthy('DEBUG_MINIFY', true)
};
Expand Down
80 changes: 80 additions & 0 deletions lib/admin_plugins/cleanentriesdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
'use strict';

var moment = require('moment');

var cleanentriesdb = {
name: 'cleanentriesdb'
, label: 'Clean Mongo entries (glucose entries) database'
, pluginType: 'admin'
};

function init() {
return cleanentriesdb;
}

module.exports = init;

cleanentriesdb.actions = [
{
name: 'Delete all documents from entries collection older than 180 days'
, description: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.'
, buttonLabel: 'Delete old documents'
, confirmText: 'Delete old documents from entries collection?'
, preventClose: true
}
];

cleanentriesdb.actions[0].init = function init(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleanentriesdb.name + '_0_status');

$status.hide();

var numDays = '<br/>'
+ '<label for="admin_entries_days">'
+ translate('Number of Days to Keep:')
+ ' <input id="admin_entries_days" value="180" size="3" min="1"/>'
+ '</label>';

$('#admin_' + cleanentriesdb.name + '_0_html').html(numDays);

if (callback) { callback(); }
};

cleanentriesdb.actions[0].code = function deleteOldRecords(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleanentriesdb.name + '_0_status');
var numDays = Number($('#admin_entries_days').val());

if (isNaN(numDays) || (numDays < 3)) {
alert(translate('%1 is not a valid number - must be more than 2', { params: [$('#admin_entries_days').val()] }));
if (callback) { callback(); }
return;
}
var endDate = moment().subtract(numDays, 'days');

if (!client.hashauth.isAuthenticated()) {
alert(translate('Your device is not authenticated yet'));
if (callback) {
callback();
}
return;
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax('/api/v1/entries/?find[date][$lte]=' + endDate.valueOf(), {
method: 'DELETE'
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
if (callback) { callback(); }
});

};
10 changes: 5 additions & 5 deletions lib/admin_plugins/cleanstatusdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ cleanstatusdb.actions[1].code = function deleteOldRecords(client, callback) {
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax({
$.ajax('/api/v1/devicestatus/?find[created_at][$lte]=' + dateStr, {
method: 'DELETE'
, url: '/api/v1/devicestatus/?find[created_at][$lte]=' + dateStr
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
$status.text(translate('%1 records deleted',{ params: [retVal.n] }));
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
$status.hide().text(translate('Error')).fadeIn('slow');
if (callback) { callback(); }
});

};
81 changes: 81 additions & 0 deletions lib/admin_plugins/cleantreatmentsdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

var moment = require('moment');

var cleantreatmentsdb = {
name: 'cleantreatmentsdb'
, label: 'Clean Mongo treatments database'
, pluginType: 'admin'
};

function init() {
return cleantreatmentsdb;
}

module.exports = init;

cleantreatmentsdb.actions = [
{
name: 'Delete all documents from treatments collection older than 180 days'
, description: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.'
, buttonLabel: 'Delete old documents'
, confirmText: 'Delete old documents from treatments collection?'
, preventClose: true
}
];

cleantreatmentsdb.actions[0].init = function init(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleantreatmentsdb.name + '_0_status');

$status.hide();

var numDays = '<br/>'
+ '<label for="admin_treatments_days">'
+ translate('Number of Days to Keep:')
+ ' <input id="admin_treatments_days" value="180" size="3" min="1"/>'
+ '</label>';

$('#admin_' + cleantreatmentsdb.name + '_0_html').html(numDays);

if (callback) { callback(); }
};

cleantreatmentsdb.actions[0].code = function deleteOldRecords(client, callback) {
var translate = client.translate;
var $status = $('#admin_' + cleantreatmentsdb.name + '_0_status');
var numDays = Number($('#admin_treatments_days').val());

if (isNaN(numDays) || (numDays < 3)) {
alert(translate('%1 is not a valid number - must be more than 2', { params: [$('#admin_treatments_days').val()] }));
if (callback) { callback(); }
return;
}
var endDate = moment().subtract(numDays, 'days');
var dateStr = endDate.format('YYYY-MM-DD');

if (!client.hashauth.isAuthenticated()) {
alert(translate('Your device is not authenticated yet'));
if (callback) {
callback();
}
return;
}

$status.hide().text(translate('Deleting records ...')).fadeIn('slow');
$.ajax('/api/v1/treatments/?find[created_at][$lte]=' + dateStr, {
method: 'DELETE'
, headers: client.headers()
, success: function (retVal) {
$status.hide().text(translate('%1 records deleted',{ params: [retVal.n] })).fadeIn('slow');
}
, error: function () {
$status.hide().text(translate('Error')).fadeIn('slow');
}
}).done(function success () {
if (callback) { callback(); }
}).fail(function fail() {
if (callback) { callback(); }
});

};
4 changes: 3 additions & 1 deletion lib/admin_plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function init() {
require('./subjects')()
, require('./roles')()
, require('./cleanstatusdb')()
, require('./cleantreatmentsdb')()
, require('./cleanentriesdb')()
, require('./futureitems')()
];

Expand Down Expand Up @@ -84,4 +86,4 @@ function init() {

}

module.exports = init;
module.exports = init;
57 changes: 36 additions & 21 deletions lib/api/devicestatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,52 @@ function configure (app, wares, ctx) {

api.post('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:create'), doPost);

api.delete('/devicestatus/:_id', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res) {
console.log('Deleting id: ' + req.params._id);

ctx.devicestatus.remove_id(req.params._id, function (err, removed) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
} else {
res.json(removed);
}
});
});

// delete record that match query
api.delete('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res) {
/**
* @function delete_records
* Delete devicestatus. The query logic works the same way as find/list. This
* endpoint uses same search logic to remove records from the database.
*/
function delete_records(req, res, next) {
var query = req.query;
if (!query.count) {
query.count = 10
}

console.log('Delete records with query: ', query);

// remove using the query
ctx.devicestatus.remove(query, function(err, stat) {
if (err) {
res.sendJSONStatus(res, consts.HTTP_INTERNAL_ERROR, 'Mongo Error', err);
console.log('Error saving treatment');
console.log(err);
} else {
res.json(stat);
console.log('devicestatus records deleted');
console.log('devicestatus delete error: ', err);
return next(err);
}
// yield some information about success of operation
res.json(stat);

console.log('devicestatus records deleted');

return next();
});
});
}

api.delete('/devicestatus/:id', ctx.authorization.isPermitted('api:devicestatus:delete'), function(req, res, next) {
if (!req.query.find) {
req.query.find = {
_id: req.params.id
};
} else {
req.query.find._id = req.params.id;
}

if (req.query.find._id === '*') {
// match any record id
delete req.query.find._id;
}
next();
}, delete_records);

// delete record that match query
api.delete('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:delete'), delete_records);
}

if (app.enabled('api') || true /*TODO: auth disabled for quick UI testing...*/) {
Expand Down
5 changes: 3 additions & 2 deletions lib/api/entries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,12 @@ curl -s -g 'http://localhost:1337/api/v1/times/20{14..15}/T{13..18}:{00..15}'.js
next();
}, delete_records);


// delete record that match query
api.delete('/entries/', ctx.authorization.isPermitted('api:entries:delete'), delete_records);
}

return api;
}

// expose module
module.exports = configure;
module.exports = configure;
Loading