TOSQUASH Continue refactoring with function
This commit is contained in:
@@ -171,19 +171,20 @@ export class ElsService {
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE
|
||||
}), {headers: this.headers})
|
||||
.map(res => {
|
||||
return res.json().hits.hits;
|
||||
})
|
||||
.map((hits: Array<any>) => {
|
||||
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<Artist> {
|
||||
|
||||
Reference in New Issue
Block a user