Added apiDoc and eslinted some code
Added basic apiDoc generation and eslinted some code.
This commit is contained in:
parent
254dd9fb71
commit
57b4e7cad0
7 changed files with 254 additions and 66 deletions
server/controllers
|
@ -10,70 +10,70 @@ const eclient = new elasticsearch.Client({
|
|||
host: 'http://localhost:9200',
|
||||
|
||||
log: {
|
||||
level: 'info',
|
||||
type: 'stream',
|
||||
level : 'info',
|
||||
type : 'stream',
|
||||
stream: loggerStream,
|
||||
},
|
||||
});
|
||||
|
||||
function getResults(input) {
|
||||
if(input.size == undefined) input.size = 10;
|
||||
if(input.from == undefined) input.from = 0;
|
||||
function getResults (input) {
|
||||
if (input.size === undefined) input.size = 10;
|
||||
if (input.from === undefined) input.from = 0;
|
||||
return eclient.search({
|
||||
index: "claims",
|
||||
body: {
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"query_string": {
|
||||
"query": input.s.trim(),
|
||||
"fields": [
|
||||
"name",
|
||||
"value.stream.metadata.author",
|
||||
"value.stream.metadata.title",
|
||||
"value.stream.metadata.description"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
index: 'claims',
|
||||
body : {
|
||||
'query': {
|
||||
'bool': {
|
||||
'must': {
|
||||
'query_string': {
|
||||
'query' : input.s.trim(),
|
||||
'fields': [
|
||||
'name',
|
||||
'value.stream.metadata.author',
|
||||
'value.stream.metadata.title',
|
||||
'value.stream.metadata.description',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
size: input.size,
|
||||
from: input.from
|
||||
}
|
||||
from: input.from,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function getAutoComplete(input) {
|
||||
if(input.size == undefined) input.size = 10;
|
||||
if(input.from == undefined) input.from = 0;
|
||||
function getAutoComplete (input) {
|
||||
if (input.size === undefined) input.size = 10;
|
||||
if (input.from === undefined) input.from = 0;
|
||||
return eclient.search({
|
||||
index: "claims",
|
||||
_source: ["name", "value.stream.metadata.title", "value.stream.metadata.author"],
|
||||
body: {
|
||||
"query": {
|
||||
"bool": {
|
||||
"must": {
|
||||
"query_string": {
|
||||
"query": input.s.trim(),
|
||||
"fields": [
|
||||
"name",
|
||||
"value.stream.metadata.title",
|
||||
"value.stream.metadata.author"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
index : 'claims',
|
||||
_source: ['name', 'value.stream.metadata.title', 'value.stream.metadata.author'],
|
||||
body : {
|
||||
'query': {
|
||||
'bool': {
|
||||
'must': {
|
||||
'query_string': {
|
||||
'query' : input.s.trim(),
|
||||
'fields': [
|
||||
'name',
|
||||
'value.stream.metadata.title',
|
||||
'value.stream.metadata.author',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
size: input.size,
|
||||
from: input.from
|
||||
}
|
||||
from: input.from,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
class LighthouseControllers {
|
||||
/* eslint-disable no-param-reassign */
|
||||
// Start syncing blocks...
|
||||
startSync() {
|
||||
startSync () {
|
||||
winston.log('info', '[Importer] Started importer, indexing claims.');
|
||||
sync();
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class LighthouseControllers {
|
|||
* Search API Endpoint.
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
async search(ctx) {
|
||||
async search (ctx) {
|
||||
await getResults(ctx.query).then(function (result) {
|
||||
let results = result.hits.hits;
|
||||
let cResults = [];
|
||||
|
@ -92,26 +92,25 @@ class LighthouseControllers {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Autocomplete API Endpoint.
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
async autoComplete(ctx) {
|
||||
async autoComplete (ctx) {
|
||||
await getAutoComplete(ctx.query).then(function (result) {
|
||||
let results = result.hits.hits;
|
||||
let cResults = [];
|
||||
for (let pResult of results) {
|
||||
cResults.push(pResult._source.name);
|
||||
if(pResult._source.value !== undefined){
|
||||
if (pResult._source.value !== undefined) {
|
||||
cResults.push(pResult._source.value.stream.metadata.title);
|
||||
cResults.push(pResult._source.value.stream.metadata.author);
|
||||
cResults.push(pResult._source.value.stream.metadata.author);
|
||||
}
|
||||
}
|
||||
|
||||
var clean = new Array();
|
||||
for (var i = 0; i < cResults.length; i++) {
|
||||
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) == -1) {
|
||||
if (cResults[i] && cResults[i].length > 3 && clean.indexOf(cResults[i]) === -1) {
|
||||
clean.push(cResults[i]);
|
||||
}
|
||||
}
|
||||
|
@ -123,19 +122,19 @@ class LighthouseControllers {
|
|||
* Info about the api here
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
async info(ctx) {
|
||||
ctx.body = "Lighthouse";
|
||||
async info (ctx) {
|
||||
ctx.body = 'Lighthouse';
|
||||
}
|
||||
|
||||
/**
|
||||
* Status of the api here
|
||||
* @param {ctx} Koa Context
|
||||
*/
|
||||
async status(ctx) {
|
||||
async status (ctx) {
|
||||
ctx.body = eclient.getStats();
|
||||
}
|
||||
|
||||
/* eslint-enable no-param-reassign */
|
||||
}
|
||||
|
||||
export default new LighthouseControllers();
|
||||
export default new LighthouseControllers();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue