From cd21d3bdb14d183f5ec26545d8f0a035dadac1ce Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Sun, 29 Oct 2017 02:02:22 +0100 Subject: [PATCH] TOSQUASH Continue refactoring with function --- dashboard/src/app/els.service.ts | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) 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 {