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