diff --git a/lib/admin_plugins/cleanentriesdb.js b/lib/admin_plugins/cleanentriesdb.js new file mode 100644 index 00000000000..3793eef8ffd --- /dev/null +++ b/lib/admin_plugins/cleanentriesdb.js @@ -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 = '
' + + ''; + + $('#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(); } + }); + +}; diff --git a/lib/admin_plugins/cleanstatusdb.js b/lib/admin_plugins/cleanstatusdb.js index f2014d69b23..b3e3032c8fe 100644 --- a/lib/admin_plugins/cleanstatusdb.js +++ b/lib/admin_plugins/cleanstatusdb.js @@ -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(); } }); - }; diff --git a/lib/admin_plugins/cleantreatmentsdb.js b/lib/admin_plugins/cleantreatmentsdb.js new file mode 100644 index 00000000000..a8cc725fd82 --- /dev/null +++ b/lib/admin_plugins/cleantreatmentsdb.js @@ -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 = '
' + + ''; + + $('#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(); } + }); + +}; diff --git a/lib/admin_plugins/index.js b/lib/admin_plugins/index.js index c6463ecca8e..224054538d1 100644 --- a/lib/admin_plugins/index.js +++ b/lib/admin_plugins/index.js @@ -8,6 +8,8 @@ function init() { require('./subjects')() , require('./roles')() , require('./cleanstatusdb')() + , require('./cleantreatmentsdb')() + , require('./cleanentriesdb')() , require('./futureitems')() ]; @@ -84,4 +86,4 @@ function init() { } -module.exports = init; \ No newline at end of file +module.exports = init; diff --git a/lib/api/devicestatus/index.js b/lib/api/devicestatus/index.js index 5ea15acf5c3..5c665b1ffc5 100644 --- a/lib/api/devicestatus/index.js +++ b/lib/api/devicestatus/index.js @@ -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...*/) { diff --git a/lib/api/entries/index.js b/lib/api/entries/index.js index dea092e6bdb..6c1e873da7f 100644 --- a/lib/api/entries/index.js +++ b/lib/api/entries/index.js @@ -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; \ No newline at end of file +module.exports = configure; diff --git a/lib/api/treatments/index.js b/lib/api/treatments/index.js index 3fff4ceb331..0362829fc7b 100644 --- a/lib/api/treatments/index.js +++ b/lib/api/treatments/index.js @@ -99,11 +99,52 @@ function configure(app, wares, ctx) { limit: 1048576 * 50 }), ctx.authorization.isPermitted('api:treatments:create'), post_response); - api.delete('/treatments/:_id', ctx.authorization.isPermitted('api:treatments:delete'), function(req, res) { - ctx.treatments.remove(req.params._id, function() { - res.json({}); - }); - }); + /** + * @function delete_records + * Delete treatments. 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.treatments.remove(query, function(err, stat) { + if (err) { + console.log('treatments delete error: ', err); + return next(err); + } + // yield some information about success of operation + res.json(stat); + + console.log('treatments records deleted'); + + return next(); + }); + } + + api.delete('/treatments/:id', ctx.authorization.isPermitted('api:treatments: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('/treatments/', ctx.authorization.isPermitted('api:treatments:delete'), delete_records); // update record api.put('/treatments/', ctx.authorization.isPermitted('api:treatments:update'), function(req, res) { diff --git a/lib/language.js b/lib/language.js index aa8914acac9..9b3c4b2d099 100644 --- a/lib/language.js +++ b/lib/language.js @@ -2319,6 +2319,30 @@ function init() { ,tr: 'Hata: Veritabanı yüklenemedi' ,zh_cn: '错误:数据库载入失败' } + ,'Error' : { + cs: 'Error' + ,he: 'Error' + ,nb: 'Error' + ,fr: 'Error' + ,ro: 'Error' + ,el: 'Error' + ,de: 'Error' + ,es: 'Error' + ,dk: 'Error' + ,sv: 'Error' + ,bg: 'Error' + ,it: 'Error' + ,fi: 'Error' + ,pl: 'Error' + ,pt: 'Error' + ,ru: 'Error' + ,sk: 'Error' + ,nl: 'Error' + ,ko: 'Error' + ,tr: 'Error' + ,zh_cn: 'Error' + ,zh_tw: 'Error' + } ,'Create new record' : { cs: 'Vytvořit nový záznam' ,de: 'Erstelle neuen Datensatz' @@ -7524,6 +7548,30 @@ function init() { ,zh_cn: '正在删除记录...' ,zh_tw: '正在刪除記錄...' } + ,'%1 records deleted' : { + cs: '%1 records deleted' + ,he: '%1 records deleted' + ,nb: '%1 records deleted' + ,fr: '%1 records deleted' + ,ro: '%1 records deleted' + ,el: '%1 records deleted' + ,de: '%1 records deleted' + ,es: '%1 records deleted' + ,dk: '%1 records deleted' + ,sv: '%1 records deleted' + ,bg: '%1 records deleted' + ,it: '%1 records deleted' + ,fi: '%1 records deleted' + ,pl: '%1 records deleted' + ,pt: '%1 records deleted' + ,ru: '%1 records deleted' + ,sk: '%1 records deleted' + ,nl: '%1 records deleted' + ,ko: '%1 records deleted' + ,tr: '%1 records deleted' + ,zh_cn: '%1 records deleted' + ,zh_tw: '%1 records deleted' + } ,'Clean Mongo status database' : { cs: 'Vyčištění Mongo databáze statusů' ,he: 'נקי מסד הנתונים מצב מונגו ' @@ -7615,7 +7663,7 @@ function init() { ,tr: 'Tüm Belgeleri sil' ,zh_cn: '删除所有文档' } - ,'Delete all documents from devicestatus collection devicestatus?' : { + ,'Delete all documents from devicestatus collection?' : { cs: 'Odstranit všechny dokumenty z kolekce devicestatus?' ,he: 'מחק את כל המסמכים מרשימת סטטוס ההתקנים ' ,nb: 'Fjern alle dokumenter fra device status tabellen?' @@ -7684,6 +7732,366 @@ function init() { ,tr: 'Tüm kayıtlar kaldırıldı ...' ,zh_cn: '所有记录已经被清除' } + ,'Delete all documents from devicestatus collection older than 30 days' : { + cs: 'Delete all documents from devicestatus collection older than 30 days' + ,he: 'Delete all documents from devicestatus collection older than 30 days' + ,nb: 'Delete all documents from devicestatus collection older than 30 days' + ,fr: 'Delete all documents from devicestatus collection older than 30 days' + ,ro: 'Delete all documents from devicestatus collection older than 30 days' + ,el: 'Delete all documents from devicestatus collection older than 30 days' + ,de: 'Delete all documents from devicestatus collection older than 30 days' + ,es: 'Delete all documents from devicestatus collection older than 30 days' + ,dk: 'Delete all documents from devicestatus collection older than 30 days' + ,sv: 'Delete all documents from devicestatus collection older than 30 days' + ,bg: 'Delete all documents from devicestatus collection older than 30 days' + ,it: 'Delete all documents from devicestatus collection older than 30 days' + ,fi: 'Delete all documents from devicestatus collection older than 30 days' + ,pl: 'Delete all documents from devicestatus collection older than 30 days' + ,pt: 'Delete all documents from devicestatus collection older than 30 days' + ,ru: 'Delete all documents from devicestatus collection older than 30 days' + ,sk: 'Delete all documents from devicestatus collection older than 30 days' + ,nl: 'Delete all documents from devicestatus collection older than 30 days' + ,ko: 'Delete all documents from devicestatus collection older than 30 days' + ,tr: 'Delete all documents from devicestatus collection older than 30 days' + ,zh_cn: 'Delete all documents from devicestatus collection older than 30 days' + ,zh_tw: 'Delete all documents from devicestatus collection older than 30 days' + } + ,'Number of Days to Keep:' : { + cs: 'Number of Days to Keep:' + ,he: 'Number of Days to Keep:' + ,nb: 'Number of Days to Keep:' + ,fr: 'Number of Days to Keep:' + ,ro: 'Number of Days to Keep:' + ,el: 'Number of Days to Keep:' + ,de: 'Number of Days to Keep:' + ,es: 'Number of Days to Keep:' + ,dk: 'Number of Days to Keep:' + ,sv: 'Number of Days to Keep:' + ,bg: 'Number of Days to Keep:' + ,it: 'Number of Days to Keep:' + ,fi: 'Number of Days to Keep:' + ,pl: 'Number of Days to Keep:' + ,pt: 'Number of Days to Keep:' + ,ru: 'Number of Days to Keep:' + ,sk: 'Number of Days to Keep:' + ,nl: 'Number of Days to Keep:' + ,ko: 'Number of Days to Keep:' + ,tr: 'Number of Days to Keep:' + ,zh_cn: 'Number of Days to Keep:' + ,zh_tw: 'Number of Days to Keep:' + } + ,'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' : { + cs: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,he: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,nb: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,fr: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,ro: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,el: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,de: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,es: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,dk: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,sv: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,bg: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,it: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,fi: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,pl: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,pt: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,ru: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,sk: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,nl: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,ko: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,tr: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,zh_cn: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + ,zh_tw: 'This task removes all documents from devicestatus collection that are older than 30 days. Useful when uploader battery status is not properly updated.' + } + ,'Delete old documents from devicestatus collection?' : { + cs: 'Delete old documents from devicestatus collection?' + ,he: 'Delete old documents from devicestatus collection?' + ,nb: 'Delete old documents from devicestatus collection?' + ,fr: 'Delete old documents from devicestatus collection?' + ,ro: 'Delete old documents from devicestatus collection?' + ,el: 'Delete old documents from devicestatus collection?' + ,de: 'Delete old documents from devicestatus collection?' + ,es: 'Delete old documents from devicestatus collection?' + ,dk: 'Delete old documents from devicestatus collection?' + ,sv: 'Delete old documents from devicestatus collection?' + ,bg: 'Delete old documents from devicestatus collection?' + ,it: 'Delete old documents from devicestatus collection?' + ,fi: 'Delete old documents from devicestatus collection?' + ,pl: 'Delete old documents from devicestatus collection?' + ,pt: 'Delete old documents from devicestatus collection?' + ,ru: 'Delete old documents from devicestatus collection?' + ,sk: 'Delete old documents from devicestatus collection?' + ,nl: 'Delete old documents from devicestatus collection?' + ,ko: 'Delete old documents from devicestatus collection?' + ,tr: 'Delete old documents from devicestatus collection?' + ,zh_cn: 'Delete old documents from devicestatus collection?' + ,zh_tw: 'Delete old documents from devicestatus collection?' + } + ,'Clean Mongo entries (glucose entries) database' : { + cs: 'Clean Mongo entries (glucose entries) database' + ,he: 'Clean Mongo entries (glucose entries) database' + ,nb: 'Clean Mongo entries (glucose entries) database' + ,fr: 'Clean Mongo entries (glucose entries) database' + ,ro: 'Clean Mongo entries (glucose entries) database' + ,el: 'Clean Mongo entries (glucose entries) database' + ,de: 'Clean Mongo entries (glucose entries) database' + ,es: 'Clean Mongo entries (glucose entries) database' + ,dk: 'Clean Mongo entries (glucose entries) database' + ,sv: 'Clean Mongo entries (glucose entries) database' + ,bg: 'Clean Mongo entries (glucose entries) database' + ,it: 'Clean Mongo entries (glucose entries) database' + ,fi: 'Clean Mongo entries (glucose entries) database' + ,pl: 'Clean Mongo entries (glucose entries) database' + ,pt: 'Clean Mongo entries (glucose entries) database' + ,ru: 'Clean Mongo entries (glucose entries) database' + ,sk: 'Clean Mongo entries (glucose entries) database' + ,nl: 'Clean Mongo entries (glucose entries) database' + ,ko: 'Clean Mongo entries (glucose entries) database' + ,tr: 'Clean Mongo entries (glucose entries) database' + ,zh_cn: 'Clean Mongo entries (glucose entries) database' + ,zh_tw: 'Clean Mongo entries (glucose entries) database' + } + ,'Delete all documents from entries collection older than 180 days' : { + cs: 'Delete all documents from entries collection older than 180 days' + ,he: 'Delete all documents from entries collection older than 180 days' + ,nb: 'Delete all documents from entries collection older than 180 days' + ,fr: 'Delete all documents from entries collection older than 180 days' + ,ro: 'Delete all documents from entries collection older than 180 days' + ,el: 'Delete all documents from entries collection older than 180 days' + ,de: 'Delete all documents from entries collection older than 180 days' + ,es: 'Delete all documents from entries collection older than 180 days' + ,dk: 'Delete all documents from entries collection older than 180 days' + ,sv: 'Delete all documents from entries collection older than 180 days' + ,bg: 'Delete all documents from entries collection older than 180 days' + ,it: 'Delete all documents from entries collection older than 180 days' + ,fi: 'Delete all documents from entries collection older than 180 days' + ,pl: 'Delete all documents from entries collection older than 180 days' + ,pt: 'Delete all documents from entries collection older than 180 days' + ,ru: 'Delete all documents from entries collection older than 180 days' + ,sk: 'Delete all documents from entries collection older than 180 days' + ,nl: 'Delete all documents from entries collection older than 180 days' + ,ko: 'Delete all documents from entries collection older than 180 days' + ,tr: 'Delete all documents from entries collection older than 180 days' + ,zh_cn: 'Delete all documents from entries collection older than 180 days' + ,zh_tw: 'Delete all documents from entries collection older than 180 days' + } + ,'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' : { + cs: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,he: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,nb: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,fr: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ro: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,el: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,de: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,es: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,dk: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,sv: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,bg: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,it: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,fi: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,pl: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,pt: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ru: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,sk: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,nl: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ko: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,tr: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,zh_cn: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,zh_tw: 'This task removes all documents from entries collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + } + ,'Delete old documents' : { + cs: 'Delete old documents' + ,he: 'Delete old documents' + ,nb: 'Delete old documents' + ,fr: 'Delete old documents' + ,ro: 'Delete old documents' + ,el: 'Delete old documents' + ,de: 'Delete old documents' + ,es: 'Delete old documents' + ,dk: 'Delete old documents' + ,sv: 'Delete old documents' + ,bg: 'Delete old documents' + ,it: 'Delete old documents' + ,fi: 'Delete old documents' + ,pl: 'Delete old documents' + ,pt: 'Delete old documents' + ,ru: 'Delete old documents' + ,sk: 'Delete old documents' + ,nl: 'Delete old documents' + ,ko: 'Delete old documents' + ,tr: 'Delete old documents' + ,zh_cn: 'Delete old documents' + ,zh_tw: 'Delete old documents' + } + ,'Delete old documents from entries collection?' : { + cs: 'Delete old documents from entries collection?' + ,he: 'Delete old documents from entries collection?' + ,nb: 'Delete old documents from entries collection?' + ,fr: 'Delete old documents from entries collection?' + ,ro: 'Delete old documents from entries collection?' + ,el: 'Delete old documents from entries collection?' + ,de: 'Delete old documents from entries collection?' + ,es: 'Delete old documents from entries collection?' + ,dk: 'Delete old documents from entries collection?' + ,sv: 'Delete old documents from entries collection?' + ,bg: 'Delete old documents from entries collection?' + ,it: 'Delete old documents from entries collection?' + ,fi: 'Delete old documents from entries collection?' + ,pl: 'Delete old documents from entries collection?' + ,pt: 'Delete old documents from entries collection?' + ,ru: 'Delete old documents from entries collection?' + ,sk: 'Delete old documents from entries collection?' + ,nl: 'Delete old documents from entries collection?' + ,ko: 'Delete old documents from entries collection?' + ,tr: 'Delete old documents from entries collection?' + ,zh_cn: 'Delete old documents from entries collection?' + ,zh_tw: 'Delete old documents from entries collection?' + } + ,'%1 is not a valid number' : { + cs: '%1 is not a valid number' + ,he: '%1 is not a valid number' + ,nb: '%1 is not a valid number' + ,fr: '%1 is not a valid number' + ,ro: '%1 is not a valid number' + ,el: '%1 is not a valid number' + ,de: '%1 is not a valid number' + ,es: '%1 is not a valid number' + ,dk: '%1 is not a valid number' + ,sv: '%1 is not a valid number' + ,bg: '%1 is not a valid number' + ,it: '%1 is not a valid number' + ,fi: '%1 is not a valid number' + ,pl: '%1 is not a valid number' + ,pt: '%1 is not a valid number' + ,ru: '%1 is not a valid number' + ,sk: '%1 is not a valid number' + ,nl: '%1 is not a valid number' + ,ko: '%1 is not a valid number' + ,tr: '%1 is not a valid number' + ,zh_cn: '%1 is not a valid number' + ,zh_tw: '%1 is not a valid number' + } + ,'%1 is not a valid number - must be more than 2' : { + cs: '%1 is not a valid number - must be more than 2' + ,he: '%1 is not a valid number - must be more than 2' + ,nb: '%1 is not a valid number - must be more than 2' + ,fr: '%1 is not a valid number - must be more than 2' + ,ro: '%1 is not a valid number - must be more than 2' + ,el: '%1 is not a valid number - must be more than 2' + ,de: '%1 is not a valid number - must be more than 2' + ,es: '%1 is not a valid number - must be more than 2' + ,dk: '%1 is not a valid number - must be more than 2' + ,sv: '%1 is not a valid number - must be more than 2' + ,bg: '%1 is not a valid number - must be more than 2' + ,it: '%1 is not a valid number - must be more than 2' + ,fi: '%1 is not a valid number - must be more than 2' + ,pl: '%1 is not a valid number - must be more than 2' + ,pt: '%1 is not a valid number - must be more than 2' + ,ru: '%1 is not a valid number - must be more than 2' + ,sk: '%1 is not a valid number - must be more than 2' + ,nl: '%1 is not a valid number - must be more than 2' + ,ko: '%1 is not a valid number - must be more than 2' + ,tr: '%1 is not a valid number - must be more than 2' + ,zh_cn: '%1 is not a valid number - must be more than 2' + ,zh_tw: '%1 is not a valid number - must be more than 2' + } + ,'Clean Mongo treatments database' : { + cs: 'Clean Mongo treatments database' + ,he: 'Clean Mongo treatments database' + ,nb: 'Clean Mongo treatments database' + ,fr: 'Clean Mongo treatments database' + ,ro: 'Clean Mongo treatments database' + ,el: 'Clean Mongo treatments database' + ,de: 'Clean Mongo treatments database' + ,es: 'Clean Mongo treatments database' + ,dk: 'Clean Mongo treatments database' + ,sv: 'Clean Mongo treatments database' + ,bg: 'Clean Mongo treatments database' + ,it: 'Clean Mongo treatments database' + ,fi: 'Clean Mongo treatments database' + ,pl: 'Clean Mongo treatments database' + ,pt: 'Clean Mongo treatments database' + ,ru: 'Clean Mongo treatments database' + ,sk: 'Clean Mongo treatments database' + ,nl: 'Clean Mongo treatments database' + ,ko: 'Clean Mongo treatments database' + ,tr: 'Clean Mongo treatments database' + ,zh_cn: 'Clean Mongo treatments database' + ,zh_tw: 'Clean Mongo treatments database' + } + ,'Delete all documents from treatments collection older than 180 days' : { + cs: 'Delete all documents from treatments collection older than 180 days' + ,he: 'Delete all documents from treatments collection older than 180 days' + ,nb: 'Delete all documents from treatments collection older than 180 days' + ,fr: 'Delete all documents from treatments collection older than 180 days' + ,ro: 'Delete all documents from treatments collection older than 180 days' + ,el: 'Delete all documents from treatments collection older than 180 days' + ,de: 'Delete all documents from treatments collection older than 180 days' + ,es: 'Delete all documents from treatments collection older than 180 days' + ,dk: 'Delete all documents from treatments collection older than 180 days' + ,sv: 'Delete all documents from treatments collection older than 180 days' + ,bg: 'Delete all documents from treatments collection older than 180 days' + ,it: 'Delete all documents from treatments collection older than 180 days' + ,fi: 'Delete all documents from treatments collection older than 180 days' + ,pl: 'Delete all documents from treatments collection older than 180 days' + ,pt: 'Delete all documents from treatments collection older than 180 days' + ,ru: 'Delete all documents from treatments collection older than 180 days' + ,sk: 'Delete all documents from treatments collection older than 180 days' + ,nl: 'Delete all documents from treatments collection older than 180 days' + ,ko: 'Delete all documents from treatments collection older than 180 days' + ,tr: 'Delete all documents from treatments collection older than 180 days' + ,zh_cn: 'Delete all documents from treatments collection older than 180 days' + ,zh_tw: 'Delete all documents from treatments collection older than 180 days' + } + ,'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' : { + cs: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,he: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,nb: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,fr: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ro: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,el: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,de: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,es: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,dk: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,sv: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,bg: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,it: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,fi: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,pl: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,pt: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ru: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,sk: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,nl: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,ko: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,tr: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,zh_cn: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + ,zh_tw: 'This task removes all documents from treatments collection that are older than 180 days. Useful when uploader battery status is not properly updated.' + } + ,'Delete old documents from treatments collection?' : { + cs: 'Delete old documents from treatments collection?' + ,he: 'Delete old documents from treatments collection?' + ,nb: 'Delete old documents from treatments collection?' + ,fr: 'Delete old documents from treatments collection?' + ,ro: 'Delete old documents from treatments collection?' + ,el: 'Delete old documents from treatments collection?' + ,de: 'Delete old documents from treatments collection?' + ,es: 'Delete old documents from treatments collection?' + ,dk: 'Delete old documents from treatments collection?' + ,sv: 'Delete old documents from treatments collection?' + ,bg: 'Delete old documents from treatments collection?' + ,it: 'Delete old documents from treatments collection?' + ,fi: 'Delete old documents from treatments collection?' + ,pl: 'Delete old documents from treatments collection?' + ,pt: 'Delete old documents from treatments collection?' + ,ru: 'Delete old documents from treatments collection?' + ,sk: 'Delete old documents from treatments collection?' + ,nl: 'Delete old documents from treatments collection?' + ,ko: 'Delete old documents from treatments collection?' + ,tr: 'Delete old documents from treatments collection?' + ,zh_cn: 'Delete old documents from treatments collection?' + ,zh_tw: 'Delete old documents from treatments collection?' + } ,'Admin Tools' : { cs: 'Nástroje pro správu' ,he: 'כלי אדמיניסטרציה ' diff --git a/lib/server/devicestatus.js b/lib/server/devicestatus.js index 43fdc055365..e74c0124841 100644 --- a/lib/server/devicestatus.js +++ b/lib/server/devicestatus.js @@ -68,17 +68,6 @@ function storage (collection, ctx) { return api( ).remove(query_for(opts), fn); } - function remove_id (_id, fn) { - var filter; - if (_id === '*') { - filter = {}; - } else { - var objId = new ObjectID(_id); - filter = { '_id': objId }; - } - return api( ).remove(filter, fn); - } - function api() { return ctx.store.collection(collection); } @@ -88,7 +77,6 @@ function storage (collection, ctx) { api.query_for = query_for; api.last = last; api.remove = remove; - api.remove_id = remove_id; api.aggregate = require('./aggregate')({ }, api); api.indexedFields = [ 'created_at' diff --git a/lib/server/entries.js b/lib/server/entries.js index 93b1b7f1ecc..84f8f234bfa 100644 --- a/lib/server/entries.js +++ b/lib/server/entries.js @@ -45,7 +45,11 @@ function storage(env, ctx) { } function remove (opts, fn) { - api( ).remove(query_for(opts), fn); + api( ).remove(query_for(opts), function (err, stat) { + //TODO: this is triggering a read from Mongo, we can do better + ctx.bus.emit('data-received'); + fn(err, stat); + }); } // return writable stream to lint each sgv record passing through it @@ -74,8 +78,6 @@ function storage(env, ctx) { //function update (fn) { //} // - //function remove (fn) { - //} // store new documents using the storage mechanism function create (docs, fn) { diff --git a/lib/server/treatments.js b/lib/server/treatments.js index eb39dbbb901..aa8f1e0d8af 100644 --- a/lib/server/treatments.js +++ b/lib/server/treatments.js @@ -96,13 +96,12 @@ function storage (env, ctx) { return find_options(opts, storage.queryOpts); } - - function remove (_id, fn) { - var objId = new ObjectID(_id); - - api( ).remove({ '_id': objId }, fn); - - ctx.bus.emit('data-received'); + function remove (opts, fn) { + return api( ).remove(query_for(opts), function (err, stat) { + //TODO: this is triggering a read from Mongo, we can do better + ctx.bus.emit('data-received'); + fn(err, stat); + }); } function save (obj, fn) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 8f29d08187d..d3c30a6b3c6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -423,7 +423,7 @@ }, "async": { "version": "0.9.2", - "resolved": "http://registry.npmjs.org/async/-/async-0.9.2.tgz", + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz", "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=" }, "async-each": { diff --git a/swagger.json b/swagger.json index 537391e3983..9c0da694029 100755 --- a/swagger.json +++ b/swagger.json @@ -577,6 +577,81 @@ "description": "Treatments to be uploaded.", "required": true } + }, + "delete": { + "tags": [ + "Treatments" + ], + "summary": "Delete treatments matching query.", + "description": "Remove treatments, same search syntax as GET.", + "operationId": "remove", + "parameters": [ + { + "name": "find", + "in": "query", + "description": "The query used to find treatments to delete, support nested query syntax, for example `find[insulin][$gte]=3`. All find parameters are interpreted as strings.", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "count", + "in": "query", + "description": "Number of entries to return.", + "required": false, + "schema": { + "type": "number" + } + } + ], + "responses": { + "200": { + "description": "Empty list is success." + } + } + } + }, + "/treatments/{spec}": { + "delete": { + "summary": "Delete treatments record with id provided in spec", + "description": "The Treatments endpoint returns information about the\nNightscout devicestatus records.\n", + "parameters": [ + { + "name": "spec", + "in": "path", + "description": "treatment id, such as `55cf81bc436037528ec75fa5`\n", + "required": true, + "schema": { + "type": "string" + } + } + ], + "tags": [ + "Treatments" + ], + "responses": { + "200": { + "description": "A status record of the delete.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/DeleteStatus" + } + } + } + }, + "default": { + "description": "Unexpected error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Error" + } + } + } + } + } } }, "/profile": { @@ -1356,4 +1431,4 @@ } } } -} +} \ No newline at end of file diff --git a/swagger.yaml b/swagger.yaml index 538fb872101..547ff8028d3 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -444,6 +444,60 @@ paths: $ref: '#/components/schemas/Treatments' description: Treatments to be uploaded. required: true + delete: + tags: + - Treatments + summary: Delete treatments matching query. + description: 'Remove treatments, same search syntax as GET.' + operationId: remove + parameters: + - name: find + in: query + description: >- + The query used to find treatments to delete, + support nested query syntax, for example `find[insulin][$gte]=3`. + All find parameters are interpreted as strings. + required: false + schema: + type: string + - name: count + in: query + description: Number of entries to return. + required: false + schema: + type: number + responses: + '200': + description: Empty list is success. + '/treatments/{spec}': + delete: + summary: Delete treatments record with id provided in spec + description: | + The Treatments endpoint returns information about the + Nightscout devicestatus records. + parameters: + - name: spec + in: path + description: | + treatment id, such as `55cf81bc436037528ec75fa5` + required: true + schema: + type: string + tags: + - Treatments + responses: + '200': + description: A status record of the delete. + content: + application/json: + schema: + $ref: '#/components/schemas/DeleteStatus' + default: + description: Unexpected error + content: + application/json: + schema: + $ref: '#/components/schemas/Error' /profile: get: summary: Profile @@ -484,10 +538,12 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - '/devicestatus/': + /devicestatus/: get: summary: All Devicestatuses matching query - description: The Devicestatus endpoint returns information about the Nightscout devicestatus records. + description: >- + The Devicestatus endpoint returns information about the Nightscout + devicestatus records. parameters: - name: find in: query @@ -658,7 +714,9 @@ components: items: $ref: '#/components/schemas/Entry' Devicestatus: - required: ['device', 'created_at'] + required: + - device + - created_at properties: device: type: string @@ -691,28 +749,28 @@ components: $ref: '#/components/schemas/pumpbattery' reservoir: type: number - description: 'Amount of insulin remaining in pump reservoir' + description: Amount of insulin remaining in pump reservoir status: $ref: '#/components/schemas/pumpstatus' pumpbattery: properties: status: type: string - description: 'Pump Battery Status String' + description: Pump Battery Status String voltage: type: number - description: 'Pump Battery Voltage Level' + description: Pump Battery Voltage Level pumpstatus: properties: status: type: string - description: 'Pump Status String' + description: Pump Status String bolusing: type: boolean - description: 'Is Pump Bolusing' + description: Is Pump Bolusing suspended: type: boolean - description: 'Is Pump Suspended' + description: Is Pump Suspended timestamp: type: string description: 'dateString, prefer ISO `8601`' @@ -720,87 +778,87 @@ components: properties: batteryVoltage: type: number - description: 'Uploader Device Battery Voltage' + description: Uploader Device Battery Voltage battery: type: number - description: 'Uploader Device Battery Percentage Charge Remaining' + description: Uploader Device Battery Percentage Charge Remaining xdripjs: properties: state: type: number - description: 'CGM Sensor Session State Code' + description: CGM Sensor Session State Code stateString: type: string - description: 'CGM Sensor Session State String' + description: CGM Sensor Session State String stateStringShort: type: string - description: 'CGM Sensor Session State Short String' + description: CGM Sensor Session State Short String txId: type: string - description: 'CGM Transmitter ID' + description: CGM Transmitter ID txStatus: type: number - description: 'CGM Transmitter Status' + description: CGM Transmitter Status txStatusString: type: string - description: 'CGM Transmitter Status String' + description: CGM Transmitter Status String txStatusStringShort: type: string - description: 'CGM Transmitter Status Short String' + description: CGM Transmitter Status Short String txActivation: type: number - description: 'CGM Transmitter Activation Milliseconds After Epoch' + description: CGM Transmitter Activation Milliseconds After Epoch mode: type: string description: 'Mode xdrip-js Application Operationg: expired, not expired, etc.' timestamp: type: number - description: 'Last Update Milliseconds After Epoch' + description: Last Update Milliseconds After Epoch rssi: type: number - description: 'Receive Signal Strength of Transmitter' + description: Receive Signal Strength of Transmitter unfiltered: type: number - description: 'Most Recent Raw Unfiltered Glucose' + description: Most Recent Raw Unfiltered Glucose filtered: type: number - description: 'Most Recent Raw Filtered Glucose' + description: Most Recent Raw Filtered Glucose noise: type: number description: 'Calculated Noise Value - 1=Clean, 2=Light, 3=Medium, 4=Heavy' noiseString: type: number - description: 'Noise Value String' + description: Noise Value String slope: type: number - description: 'Calibration Slope Value' + description: Calibration Slope Value intercept: type: number - description: 'Calibration Intercept Value' + description: Calibration Intercept Value calType: type: string - description: 'Algorithm Used to Calculate Calibration Values' + description: Algorithm Used to Calculate Calibration Values lastCalibrationDate: type: number - description: 'Most Recent Calibration Milliseconds After Epoch' + description: Most Recent Calibration Milliseconds After Epoch sessionStart: type: number - description: 'Sensor Session Start Milliseconds After Epoch' + description: Sensor Session Start Milliseconds After Epoch batteryTimestamp: type: number - description: 'Most Recent Batter Status Read Milliseconds After Epoch' + description: Most Recent Batter Status Read Milliseconds After Epoch voltagea: type: number - description: 'Voltage of Battery A' + description: Voltage of Battery A voltageb: type: number - description: 'Voltage of Battery B' + description: Voltage of Battery B temperature: type: number - description: 'Transmitter Temperature' + description: Transmitter Temperature resistance: type: number - description: 'Sensor Resistance' + description: Sensor Resistance Treatment: properties: _id: @@ -984,32 +1042,31 @@ components: type: object DeleteStatus: properties: - n: + 'n': type: integer format: int32 - description: 'Number of records deleted' + description: Number of records deleted optime: $ref: '#/components/schemas/optime' electionId: type: string - description: 'Election id of operation' + description: Election id of operation ok: type: integer format: int32 - description: 'Status of whether delete was successful' + description: Status of whether delete was successful operationTime: type: string - description: 'Time delete operation was executed' + description: Time delete operation was executed $clusterTime: type: string - description: 'Information about execution time in cluster environment' + description: Information about execution time in cluster environment optime: properties: ts: type: string - description: 'Time the operation started' + description: Time the operation started t: type: integer format: int32 - description: 'Time the operation took to complete' - + description: Time the operation took to complete diff --git a/tests/admintools.test.js b/tests/admintools.test.js index b5be4858edb..2c2924c4a8c 100644 --- a/tests/admintools.test.js +++ b/tests/admintools.test.js @@ -29,6 +29,9 @@ var someData = { 'created_at': '2025-09-28T16:41:07.144Z' } ], + '/api/v1/devicestatus/?find[created_at][$lte]=': { + n: 1 + }, '/api/v1/treatments.json?&find[created_at][$gte]=': [ { '_id': '5609a9203c8104a8195b1c1e', @@ -38,6 +41,9 @@ var someData = { 'created_at': '2025-09-28T20:54:00.000Z' } ], + '/api/v1/treatments/?find[created_at][$lte]=': { + n: 1 + }, '/api/v1/entries.json?&find[date][$gte]=': [ { '_id': '560983f326c5a592d9b9ae0c', @@ -51,8 +57,11 @@ var someData = { 'rssi': 178, 'noise': 1 } - ] - }; + ], + '/api/v1/entries/?find[date][$lte]=': { + n: 1 + }, +}; describe('admintools', function ( ) { @@ -98,9 +107,14 @@ describe('admintools', function ( ) { if (opts && opts.success && opts.success.call) { if (url.indexOf('/api/v1/treatments.json?&find[created_at][$gte]=')===0) { url = '/api/v1/treatments.json?&find[created_at][$gte]='; - } - if (url.indexOf('/api/v1/entries.json?&find[date][$gte]=')===0) { + } else if (url.indexOf('/api/v1/entries.json?&find[date][$gte]=')===0) { url = '/api/v1/entries.json?&find[date][$gte]='; + } else if (url.indexOf('/api/v1/devicestatus/?find[created_at][$lte]=')===0) { + url = '/api/v1/devicestatus/?find[created_at][$lte]='; + } else if (url.indexOf('/api/v1/treatments/?find[created_at][$lte]=')===0) { + url = '/api/v1/treatments/?find[created_at][$lte]='; + } else if (url.indexOf('/api/v1/entries/?find[date][$lte]=')===0) { + url = '/api/v1/entries/?find[date][$lte]='; } return { done: function mockDone (fn) { @@ -219,6 +233,12 @@ describe('admintools', function ( ) { $('#admin_cleanstatusdb_0_html + button').click(); $('#admin_cleanstatusdb_0_status').text().should.equal('All records removed ...'); // devicestatus code result + $('#admin_cleanstatusdb_1_html + button').text().should.equal('Delete old documents'); // devicestatus button + $('#admin_cleanstatusdb_1_status').text().should.equal(''); // devicestatus init result + + $('#admin_cleanstatusdb_1_html + button').click(); + $('#admin_cleanstatusdb_1_status').text().should.equal('1 records deleted'); // devicestatus code result + $('#admin_futureitems_0_html + button').text().should.equal('Remove treatments in the future'); // futureitems button 0 $('#admin_futureitems_0_status').text().should.equal('Database contains 1 future records'); // futureitems init result 0 @@ -231,6 +251,18 @@ describe('admintools', function ( ) { $('#admin_futureitems_1_html + button').click(); $('#admin_futureitems_1_status').text().should.equal('Record 560983f326c5a592d9b9ae0c removed ...'); // futureitems code result 1 + $('#admin_cleantreatmentsdb_0_html + button').text().should.equal('Delete old documents'); // treatments button + $('#admin_cleantreatmentsdb_0_status').text().should.equal(''); // treatments init result + + $('#admin_cleantreatmentsdb_0_html + button').click(); + $('#admin_cleantreatmentsdb_0_status').text().should.equal('1 records deleted'); // treatments code result + + $('#admin_cleanentriesdb_0_html + button').text().should.equal('Delete old documents'); // entries button + $('#admin_cleanentriesdb_0_status').text().should.equal(''); // entries init result + + $('#admin_cleanentriesdb_0_html + button').click(); + $('#admin_cleanentriesdb_0_status').text().should.equal('1 records deleted'); // entries code result + done(); });