diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index f8a1473..d6a73e7 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -250,13 +250,7 @@ export class ElsService { 'size': 0 }), {headers: this.headers}) .map(res => res.json().aggregations.genres.buckets) - .map((hits: Array) => { - const result: Array = []; - hits.forEach((bucket) => { - result.push(bucket); - }); - return result; - }); + .map((hits: Array) => this.hitsToBuckets(hits)); } getGenreCount(): Observable { @@ -299,14 +293,15 @@ export class ElsService { 'size': 0 }), {headers: this.headers}) .map(res => res.json().aggregations.album.buckets) - .map((hits: Array) => { - // TODO Refactor this duplicated code to a method - const result: Array = []; - hits.forEach((bucket) => { - result.push(bucket); - }); - return result; + .map((hits: Array) => this.hitsToBuckets(hits)); + } + + private hitsToBuckets(hits: Array): Bucket[] { + const result: Array = []; + hits.forEach((bucket) => { + result.push(bucket); }); + return result; } private handleError(error: any): Promise {