Little improve service (code style)

This commit is contained in:
2017-05-05 05:03:25 +02:00
parent f58113ca22
commit d099353aed

View File

@@ -118,7 +118,8 @@ export class ElsService {
console.debug("getArtistSongs- Artist name: " + artistName + " - from: " + from); console.debug("getArtistSongs- Artist name: " + artistName + " - from: " + from);
return this.http return this.http
.post(this.elsUrl + "song/_search", .post(this.elsUrl + "song/_search",
JSON.stringify({ JSON.stringify(
{
"query": { "query": {
"bool": { "bool": {
"should": [ "should": [
@@ -129,7 +130,7 @@ export class ElsService {
}, },
"size": ElsService.DEFAULT_SIZE, "size": ElsService.DEFAULT_SIZE,
"from": from "from": from
}), }),
{headers: this.headers}) {headers: this.headers})
.map(res => { .map(res => {
return res.json().hits.hits; return res.json().hits.hits;
@@ -157,7 +158,7 @@ export class ElsService {
return undefined; return undefined;
} }
if (hits.length > 1) { if (hits.length > 1) {
console.error('More than one album "' + albumName + '" found, return the first.'); console.error('More than one album "' + albumName + '" found (' + hits.length + '), return the first.');
} }
return hits[0]._source; return hits[0]._source;
}); });
@@ -172,12 +173,13 @@ export class ElsService {
.map((hits: Array<any>) => { .map((hits: Array<any>) => {
// Theorically, my script prevent to found two documents with this query. // Theorically, my script prevent to found two documents with this query.
// But Prevention is better than cure as Shakespeare said // But Prevention is better than cure as Shakespeare said
console.log(hits.length);
if (hits.length < 1) { if (hits.length < 1) {
console.info('No artist "' + artistName + '" found.'); console.info('No artist "' + artistName + '" found.');
return undefined; return undefined;
} }
if (hits.length > 1) { if (hits.length > 1) {
console.error('More than one artist "' + artistName + '" found, return the first.'); console.error('More than one artist "' + artistName + '" found (' + hits.length + '), return the first.');
console.error('This is not normal!') console.error('This is not normal!')
} }
return hits[0]._source; return hits[0]._source;