diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index 38a8032..7f5399a 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -171,19 +171,20 @@ export class ElsService { }, 'size': ElsService.DEFAULT_SIZE }), {headers: this.headers}) - .map(res => { - return res.json().hits.hits; - }) - .map((hits: Array) => { - if (hits.length < 1) { - console.info('No album "' + albumName + '" found.'); - return undefined; - } - if (hits.length > 1) { - console.error('More than one album "' + albumName + '" found (' + hits.length + '), return the first.'); - } - return hits[0]._source; - }); + .map(res => this.responseToAlbum(res, albumName)); + } + + private responseToAlbum(res: Response, name: string): Album { + const hits = res.json().hits.hits; + if (hits.length < 1) { + console.info('No album "' + name + '" found.'); + return undefined; + } + if (hits.length > 1) { + // TODO Cumul results + console.error('More than one album "' + name + '" found (' + hits.length + '), return the first.'); + } + return hits[0]._source; } getArtist(artistName: string): Observable {