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