ELS Service Refactor: extract method to treat hits buckets
This commit is contained in:
@@ -250,13 +250,7 @@ export class ElsService {
|
|||||||
'size': 0
|
'size': 0
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => res.json().aggregations.genres.buckets)
|
.map(res => res.json().aggregations.genres.buckets)
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||||
const result: Array<Bucket> = [];
|
|
||||||
hits.forEach((bucket) => {
|
|
||||||
result.push(bucket);
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getGenreCount(): Observable<number> {
|
getGenreCount(): Observable<number> {
|
||||||
@@ -299,14 +293,15 @@ export class ElsService {
|
|||||||
'size': 0
|
'size': 0
|
||||||
}), {headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => res.json().aggregations.album.buckets)
|
.map(res => res.json().aggregations.album.buckets)
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => this.hitsToBuckets(hits));
|
||||||
// TODO Refactor this duplicated code to a method
|
}
|
||||||
|
|
||||||
|
private hitsToBuckets(hits: Array<any>): Bucket[] {
|
||||||
const result: Array<Bucket> = [];
|
const result: Array<Bucket> = [];
|
||||||
hits.forEach((bucket) => {
|
hits.forEach((bucket) => {
|
||||||
result.push(bucket);
|
result.push(bucket);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: any): Promise<any> {
|
private handleError(error: any): Promise<any> {
|
||||||
|
|||||||
Reference in New Issue
Block a user