mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
Fix eslint errors and add npm script for eslint (#5427)
* re-enable auth check for device status routes * Resolve eslint errors * Add npm script for eslint * Correct regex for express extension middleware and add tests for expected behaviour * Resolve lint error in virtual assistant base * Update index.js * Update index.js
This commit is contained in:
@@ -43,17 +43,17 @@ function configure(app, wares, ctx) {
|
||||
|
||||
var d2 = null;
|
||||
|
||||
if (t.hasOwnProperty('created_at')) {
|
||||
if (Object.prototype.hasOwnProperty.call(t, 'created_at')) {
|
||||
d2 = new Date(t.created_at);
|
||||
} else {
|
||||
if (t.hasOwnProperty('timestamp')) {
|
||||
if (Object.prototype.hasOwnProperty.call(t, 'timestamp')) {
|
||||
d2 = new Date(t.timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
if (d2 == null) { return; }
|
||||
|
||||
if (d1 == null || d2.getTime() > d1.getTime()) {
|
||||
if (d1 == null || d2.getTime() > d1.getTime()) {
|
||||
d1 = d2;
|
||||
}
|
||||
});
|
||||
@@ -80,7 +80,7 @@ function configure(app, wares, ctx) {
|
||||
|
||||
if (!_isArray(activity)) {
|
||||
activity = [activity];
|
||||
};
|
||||
}
|
||||
|
||||
ctx.activity.create(activity, function(err, created) {
|
||||
if (err) {
|
||||
|
||||
@@ -118,4 +118,4 @@ function configure (app, wares, ctx, env) {
|
||||
return api;
|
||||
}
|
||||
|
||||
module.exports = configure;
|
||||
module.exports = configure;
|
||||
|
||||
@@ -105,7 +105,7 @@ function configure (app, wares, ctx, env) {
|
||||
api.delete('/devicestatus/', ctx.authorization.isPermitted('api:devicestatus:delete'), delete_records);
|
||||
}
|
||||
|
||||
if (app.enabled('api') || true /*TODO: auth disabled for quick UI testing...*/ ) {
|
||||
if (app.enabled('api')) {
|
||||
config_authed(app, api, wares, ctx);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,4 +54,4 @@ function configure (app, wares, ctx, env) {
|
||||
return api;
|
||||
}
|
||||
|
||||
module.exports = configure;
|
||||
module.exports = configure;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ function configure (app, wares, env, ctx) {
|
||||
// Status badge/text/json
|
||||
api.get('/status', function (req, res) {
|
||||
|
||||
var authToken = req.query.token || req.query.secret || '';
|
||||
var authToken = req.query.token || req.query.secret || '';
|
||||
|
||||
var date = new Date();
|
||||
var info = { status: 'ok'
|
||||
|
||||
@@ -53,10 +53,10 @@ function configure (app, wares, ctx, env) {
|
||||
|
||||
var d2 = null;
|
||||
|
||||
if (t.hasOwnProperty('created_at')) {
|
||||
if (Object.prototype.hasOwnProperty.call(t, 'created_at')) {
|
||||
d2 = new Date(t.created_at);
|
||||
} else {
|
||||
if (t.hasOwnProperty('timestamp')) {
|
||||
if (Object.prototype.hasOwnProperty.call(t, 'timestamp')) {
|
||||
d2 = new Date(t.timestamp);
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ function configure (app, wares, ctx, env) {
|
||||
|
||||
if (!_isArray(treatments)) {
|
||||
treatments = [treatments];
|
||||
};
|
||||
}
|
||||
|
||||
ctx.treatments.create(treatments, function(err, created) {
|
||||
if (err) {
|
||||
|
||||
@@ -186,7 +186,7 @@ function init (env, ctx) {
|
||||
authorization.isPermitted = function isPermitted (permission, opts) {
|
||||
|
||||
|
||||
opts = mkopts(opts);
|
||||
mkopts(opts);
|
||||
authorization.seenPermissions = _.chain(authorization.seenPermissions)
|
||||
.push(permission)
|
||||
.sort()
|
||||
|
||||
@@ -24,7 +24,7 @@ function init (env, ctx) {
|
||||
|
||||
function create (collection) {
|
||||
function doCreate(obj, fn) {
|
||||
if (!obj.hasOwnProperty('created_at')) {
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, 'created_at')) {
|
||||
obj.created_at = (new Date()).toISOString();
|
||||
}
|
||||
collection.insert(obj, function (err, doc) {
|
||||
@@ -211,14 +211,14 @@ function init (env, ctx) {
|
||||
if (!accessToken) return null;
|
||||
|
||||
var split_token = accessToken.split('-');
|
||||
var prefix = split_token ? _.last(split_token) : '';
|
||||
var prefix = split_token ? _.last(split_token) : '';
|
||||
|
||||
if (prefix.length < 16) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _.find(storage.subjects, function matches (subject) {
|
||||
return subject.accessTokenDigest.indexOf(accessToken) === 0 || subject.digest.indexOf(prefix) === 0;
|
||||
return subject.accessTokenDigest.indexOf(accessToken) === 0 || subject.digest.indexOf(prefix) === 0;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -730,8 +730,6 @@ function init (client, d3, $) {
|
||||
// on the number of hours the user has selected to show
|
||||
var forecastMills = Math.min(availForecastMills, maxForecastMills);
|
||||
|
||||
var lastSGVMills = client.sbx.lastSGVMills();
|
||||
|
||||
// Don't allow the forecast time to go below the minimum forecast time
|
||||
client.forecastTime = Math.max(forecastMills, minForecastMills);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ module.exports = function calcDelta (oldData, newData) {
|
||||
var result = [];
|
||||
l = newArray.length;
|
||||
for (var j = 0; j < l; j++) {
|
||||
if (!seen.hasOwnProperty(newArray[j].mills)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(seen, newArray[j].mills)) {
|
||||
result.push(newArray[j]);
|
||||
}
|
||||
}
|
||||
@@ -94,12 +94,12 @@ module.exports = function calcDelta (oldData, newData) {
|
||||
var changesFound = false;
|
||||
|
||||
for (var array in compressibleArrays) {
|
||||
if (compressibleArrays.hasOwnProperty(array)) {
|
||||
if (Object.prototype.hasOwnProperty.call(compressibleArrays, array)) {
|
||||
var a = compressibleArrays[array];
|
||||
if (newData.hasOwnProperty(a)) {
|
||||
if (Object.prototype.hasOwnProperty.call(newData, a)) {
|
||||
|
||||
// if previous data doesn't have the property (first time delta?), just assign data over
|
||||
if (!oldData.hasOwnProperty(a)) {
|
||||
if (!Object.prototype.hasOwnProperty.call(oldData, a)) {
|
||||
delta[a] = newData[a];
|
||||
changesFound = true;
|
||||
continue;
|
||||
@@ -125,9 +125,9 @@ module.exports = function calcDelta (oldData, newData) {
|
||||
var changesFound = false;
|
||||
|
||||
for (var object in skippableObjects) {
|
||||
if (skippableObjects.hasOwnProperty(object)) {
|
||||
if (Object.prototype.hasOwnProperty.call(skippableObjects, object)) {
|
||||
var o = skippableObjects[object];
|
||||
if (newData.hasOwnProperty(o)) {
|
||||
if (Object.prototype.hasOwnProperty.call(newData, o)) {
|
||||
if (JSON.stringify(newData[o]) !== JSON.stringify(oldData[o])) {
|
||||
//console.log('delta changes found on', o);
|
||||
changesFound = true;
|
||||
|
||||
@@ -192,7 +192,6 @@ function loadActivity(ddata, ctx, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
var activity = [];
|
||||
ctx.activity.list(q, function(err, results) {
|
||||
|
||||
if (err) {
|
||||
|
||||
@@ -16,7 +16,7 @@ module.exports = function (formats) {
|
||||
throw new Error('Invalid format.')
|
||||
})
|
||||
|
||||
var regexp = new RegExp('\.(' + formats.join('|') + ')$', 'i')
|
||||
var regexp = new RegExp('\\.(' + formats.join('|') + ')$', 'i')
|
||||
|
||||
return function (req, res, next) {
|
||||
var match = req.path.match(regexp)
|
||||
|
||||
@@ -10,7 +10,7 @@ function extensions (list) {
|
||||
return require('./express-extension-to-accept')(list);
|
||||
}
|
||||
|
||||
function configure (env) {
|
||||
function configure () {
|
||||
return {
|
||||
sendJSONStatus: wares.sendJSONStatus( ),
|
||||
bodyParser: wares.bodyParser,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
|
||||
function init (env, ctx) {
|
||||
function init () {
|
||||
console.log('Configuring Alexa...');
|
||||
function alexa() {
|
||||
return alexa;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
|
||||
function init (env, ctx) {
|
||||
function init () {
|
||||
console.log('Configuring Google Home...');
|
||||
function googleHome() {
|
||||
return googleHome;
|
||||
|
||||
@@ -28,7 +28,7 @@ function init(env, ctx) {
|
||||
moment(records[0].date).from(moment(sbx.time))
|
||||
]
|
||||
});
|
||||
|
||||
|
||||
callback(null, {results: status, priority: -1});
|
||||
});
|
||||
}, 'BG Status');
|
||||
@@ -40,7 +40,7 @@ function init(env, ctx) {
|
||||
});
|
||||
|
||||
// blood sugar and direction
|
||||
configuredPlugin.configureIntentHandler('MetricNow', function (callback, slots, sbx, locale) {
|
||||
configuredPlugin.configureIntentHandler('MetricNow', function (callback, slots, sbx) {
|
||||
entries.list({count: 1}, function(err, records) {
|
||||
var direction;
|
||||
if(translate(records[0].direction)){
|
||||
@@ -54,13 +54,13 @@ function init(env, ctx) {
|
||||
direction,
|
||||
moment(records[0].date).from(moment(sbx.time))]
|
||||
});
|
||||
|
||||
|
||||
callback(translate('virtAsstTitleCurrentBG'), status);
|
||||
});
|
||||
}, ['bg', 'blood glucose', 'number']);
|
||||
|
||||
|
||||
// blood sugar delta
|
||||
configuredPlugin.configureIntentHandler('MetricNow', function (callback, slots, sbx, locale) {
|
||||
configuredPlugin.configureIntentHandler('MetricNow', function (callback, slots, sbx) {
|
||||
if (sbx.properties.delta && sbx.properties.delta.display) {
|
||||
entries.list({count: 2}, function(err, records) {
|
||||
callback(
|
||||
@@ -108,4 +108,4 @@ function init(env, ctx) {
|
||||
return virtAsstBase;
|
||||
}
|
||||
|
||||
module.exports = init;
|
||||
module.exports = init;
|
||||
|
||||
@@ -443,15 +443,9 @@ function init (env, ctx, server) {
|
||||
socketAuthorization = authorization;
|
||||
clientType = message.client;
|
||||
history = message.history || 48; //default history is 48 hours
|
||||
var from = message.from;
|
||||
|
||||
if (socketAuthorization.read) {
|
||||
socket.join('DataReceivers');
|
||||
var msecHistory = times.hours(history).msecs;
|
||||
// if `from` is received, it's a reconnection and full data is not needed
|
||||
if (from && from > 0) {
|
||||
msecHistory = Math.min(new Date().getTime() - from, msecHistory);
|
||||
}
|
||||
|
||||
if (lastData && lastData.dataWithRecentStatuses) {
|
||||
let data = lastData.dataWithRecentStatuses();
|
||||
|
||||
+2
-1
@@ -37,7 +37,8 @@
|
||||
"update-buster": "node bin/generateCacheBuster.js >tmp/cacheBusterToken",
|
||||
"coverage": "cat ./coverage/lcov.info | env-cmd ./ci.test.env codacy-coverage",
|
||||
"dev": "env-cmd ./my.env nodemon server.js 0.0.0.0",
|
||||
"prod": "env-cmd ./my.prod.env node server.js 0.0.0.0"
|
||||
"prod": "env-cmd ./my.prod.env node server.js 0.0.0.0",
|
||||
"lint": "eslint lib"
|
||||
},
|
||||
"main": "server.js",
|
||||
"config": {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
require('should');
|
||||
|
||||
var extensionsMiddleware = require('../lib/middleware/express-extension-to-accept.js');
|
||||
|
||||
var acceptJsonRequests = extensionsMiddleware(['json']);
|
||||
|
||||
describe('Express extension middleware', function ( ) {
|
||||
|
||||
it('Valid json request should be given accept header for application/json', function () {
|
||||
var entriesRequest = {
|
||||
path: '/api/v1/entries.json',
|
||||
url: '/api/v1/entries.json',
|
||||
headers: {}
|
||||
};
|
||||
|
||||
acceptJsonRequests(entriesRequest, {}, () => {});
|
||||
entriesRequest.headers.accept.should.equal('application/json');
|
||||
});
|
||||
|
||||
it('Invalid json request should NOT be given accept header', function () {
|
||||
var invalidEntriesRequest = {
|
||||
path: '/api/v1/entriesXjson',
|
||||
url: '/api/v1/entriesXjson',
|
||||
headers: {}
|
||||
};
|
||||
|
||||
acceptJsonRequests(invalidEntriesRequest, {}, () => {});
|
||||
should(invalidEntriesRequest.headers.accept).not.be.ok;
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user