TOSQUASH Continue refactoring with function

This commit is contained in:
2017-10-29 02:02:22 +01:00
parent 8fd9466fb1
commit cd21d3bdb1

View File

@@ -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> {