Skip to content

Commit

Permalink
eslint errors fix
Browse files Browse the repository at this point in the history
  • Loading branch information
schatzopoulos committed Feb 17, 2017
1 parent 5420e85 commit b361876
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 96 deletions.
3 changes: 1 addition & 2 deletions application/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"no-var": 1,
"no-warning-comments": 0,
"promise/param-names": 1,
"promise/always-return": 0,
"promise/always-catch": 1
"promise/catch-or-return": 1
},
"plugins": [
"promise"
Expand Down
90 changes: 45 additions & 45 deletions application/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@
'use strict';

module.exports = {
isEmpty: function(toTest) {
return (toTest === undefined ||
toTest === null ||
toTest === '' ||
(toTest instanceof Object && Object.keys(toTest).length === 0) ||
(toTest instanceof Array && toTest.length === 0));
},
isEmpty: function(toTest) {
return (toTest === undefined ||
toTest === null ||
toTest === '' ||
(toTest instanceof Object && Object.keys(toTest).length === 0) ||
(toTest instanceof Array && toTest.length === 0));
},

rewriteID: function(o){
if(!this.isEmpty(o)){
o.id = o._id;
delete o._id;
}
return o;
},
rewriteID: function(o){
if(!this.isEmpty(o)){
o.id = o._id;
delete o._id;
}
return o;
},

parseAjvValidationErrors: function(array) {
const beautifyKey = (key) => {
if (key.startsWith('.'))
key = key.substring(1, key.length);
if (key.endsWith(']') && key.indexOf('[') !== -1)
key = key.substring(0, key.indexOf('['));
return key;
};
parseAjvValidationErrors: function(array) {
const beautifyKey = (key) => {
if (key.startsWith('.'))
key = key.substring(1, key.length);
if (key.endsWith(']') && key.indexOf('[') !== -1)
key = key.substring(0, key.indexOf('['));
return key;
};

if (this.isEmpty(array))
return null;
if (this.isEmpty(array))
return null;

return array.reduce((prev, curr) => {
if (curr.keyword === 'required') {
prev.missing[beautifyKey(curr.params.missingProperty)] = curr;
} else {
let key = beautifyKey((curr.dataPath !== '') ? curr.dataPath : curr.schemaPath);
if (curr.dataPath === '' && curr.params.key)
key += ' with key ' + curr.params.key;
return array.reduce((prev, curr) => {
if (curr.keyword === 'required') {
prev.missing[beautifyKey(curr.params.missingProperty)] = curr;
} else {
let key = beautifyKey((curr.dataPath !== '') ? curr.dataPath : curr.schemaPath);
if (curr.dataPath === '' && curr.params.key)
key += ' with key ' + curr.params.key;

if (prev.wrong[key]) {
//already given so increment counter
prev.wrong[key].occurences = 1 + prev.wrong[key].occurences;
} else {
curr.occurences = 1;
prev.wrong[key] = curr;
}
}
return prev;
}, {
missing: {},
wrong: {}
});
}
if (prev.wrong[key]) {
//already given so increment counter
prev.wrong[key].occurences = 1 + prev.wrong[key].occurences;
} else {
curr.occurences = 1;
prev.wrong[key] = curr;
}
}
return prev;
}, {
missing: {},
wrong: {}
});
}
};
5 changes: 2 additions & 3 deletions application/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"main": "server.js",
"scripts": {
"clean": "rm -R ./node_modules/ ./coverage/",
"lint": "eslint -c .eslintrc ./**/*.js",
"lint": "eslint -c .eslintrc \"./**/*.js\"",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "mocha ./tests/unit_*.js",
"test:integration": "mocha ./tests/integration_*.js",
Expand All @@ -39,8 +39,7 @@
"vision": "^4.1.1",
"solr-client": "^0.6.0",
"mongo-trigger": "^0.1.5",
"request": "^2.74.0",
"html-to-text": "^2.1.3",
"html-to-text": "^3.1.0",
"request-promise": "^4.1.1"
},
"engines": {
Expand Down
92 changes: 46 additions & 46 deletions application/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ This application demonstrates a service which returns previously inserted data f

//This is our webserver framework (instead of express)
const hapi = require('hapi'),
co = require('./common'),
decksListener = require('./mongoListeners/decksListener'),
slidesListener = require('./mongoListeners/slidesListener'),
usersListener = require('./mongoListeners/usersListener');
co = require('./common'),
decksListener = require('./mongoListeners/decksListener'),
slidesListener = require('./mongoListeners/slidesListener'),
usersListener = require('./mongoListeners/usersListener');

//Initiate the webserver with standard or given port
const server = new hapi.Server({ connections: {routes: {validate: { options: {convert : false}}}}});

let port = (!co.isEmpty(process.env.APPLICATION_PORT)) ? process.env.APPLICATION_PORT : 4000;
server.connection({
port: port
port: port
});
let host = (!co.isEmpty(process.env.VIRTUAL_HOST)) ? process.env.VIRTUAL_HOST : server.info.host;

Expand All @@ -26,38 +26,38 @@ module.exports = server;

//Plugin for sweet server console output
let plugins = [
require('inert'),
require('vision'), {
register: require('good'),
options: {
ops: {
interval: 1000
},
reporters: {
console: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{
log: '*',
response: '*',
request: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
}
require('inert'),
require('vision'), {
register: require('good'),
options: {
ops: {
interval: 1000
},
reporters: {
console: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{
log: '*',
response: '*',
request: '*'
}]
}, {
module: 'good-console'
}, 'stdout']
}
}
}, { //Plugin for swagger API documentation
register: require('hapi-swagger'),
options: {
host: host,
info: {
title: 'Search Service API',
description: 'Powered by node, hapi, joi, hapi-swaggered, hapi-swaggered-ui and swagger-ui',
version: '0.1.0'
}
}
}
}, { //Plugin for swagger API documentation
register: require('hapi-swagger'),
options: {
host: host,
info: {
title: 'Search Service API',
description: 'Powered by node, hapi, joi, hapi-swaggered, hapi-swaggered-ui and swagger-ui',
version: '0.1.0'
}
}
}
];

// start listening to mongo changes
Expand All @@ -67,14 +67,14 @@ usersListener.listen();

//Register plugins and start webserver
server.register(plugins, (err) => {
if (err) {
console.error(err);
global.process.exit();
} else {
server.start(() => {
server.log('info', 'Server started at ' + server.info.uri);
//Register routes
require('./routes.js')(server);
});
}
if (err) {
console.error(err);
global.process.exit();
} else {
server.start(() => {
server.log('info', 'Server started at ' + server.info.uri);
//Register routes
require('./routes.js')(server);
});
}
});

0 comments on commit b361876

Please sign in to comment.