Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions lib/api/activity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
Expand All @@ -80,7 +80,7 @@ function configure(app, wares, ctx) {

if (!_isArray(activity)) {
activity = [activity];
};
}

ctx.activity.create(activity, function(err, created) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/api/alexa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ function configure (app, wares, ctx, env) {
return api;
}

module.exports = configure;
module.exports = configure;
2 changes: 1 addition & 1 deletion lib/api/devicestatus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/api/googlehome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ function configure (app, wares, ctx, env) {
return api;
}

module.exports = configure;
module.exports = configure;
2 changes: 1 addition & 1 deletion lib/api/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions lib/api/treatments/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ function configure (app, wares, ctx, env) {

if (!_isArray(treatments)) {
treatments = [treatments];
};
}

ctx.treatments.create(treatments, function(err, created) {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/authorization/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions lib/authorization/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
});
};

Expand Down
2 changes: 0 additions & 2 deletions lib/client/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/data/calcdelta.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion lib/data/dataloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ function loadActivity(ddata, ctx, callback) {
}
};

var activity = [];
ctx.activity.list(q, function(err, results) {

if (err) {
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/express-extension-to-accept.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/alexa.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/googlehome.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
12 changes: 6 additions & 6 deletions lib/plugins/virtAsstBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function init(env, ctx) {
moment(records[0].date).from(moment(sbx.time))
]
});

callback(null, {results: status, priority: -1});
});
}, 'BG Status');
Expand All @@ -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)){
Expand All @@ -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(
Expand Down Expand Up @@ -108,4 +108,4 @@ function init(env, ctx) {
return virtAsstBase;
}

module.exports = init;
module.exports = init;
6 changes: 0 additions & 6 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
33 changes: 33 additions & 0 deletions tests/expressextensions.test.js
Original file line number Diff line number Diff line change
@@ -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;
});

});