Finish to refactor
This commit is contained in:
@@ -202,8 +202,7 @@ export class ElsService {
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().aggregations.genres.buckets)
|
||||
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||
.map(res => this.responseAggregationToBucket(res, 'genres'));
|
||||
}
|
||||
|
||||
getGenreCount(): Observable<number> {
|
||||
@@ -245,9 +244,8 @@ export class ElsService {
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.map(res => res.json().aggregations.album.buckets)
|
||||
.map(res => this.responseAggregationToBucket(res, 'album'));
|
||||
// TODO Take in consideration "sum_other_doc_count"
|
||||
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||
}
|
||||
|
||||
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
|
||||
@@ -304,12 +302,17 @@ export class ElsService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private hitsToBuckets(hits: Array<any>): Bucket[] {
|
||||
const result: Array<Bucket> = [];
|
||||
hits.forEach((bucket) => {
|
||||
result.push(bucket);
|
||||
});
|
||||
return result;
|
||||
/** Process an aggregation response to an array of Bucket.
|
||||
*
|
||||
* @param res Response to process
|
||||
* @param name Name of aggregation
|
||||
*/
|
||||
private responseAggregationToBucket(res: Response, name: string): Bucket[] {
|
||||
const result: Array<Bucket> = [];
|
||||
res.json().aggregations[name].buckets.forEach((bucket) => {
|
||||
result.push(bucket);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
private handleError(error: any): Promise<any> {
|
||||
|
||||
Reference in New Issue
Block a user