From 50bc795d5f1494ddccd4f35dd21882ad171bd0c5 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Thu, 5 Oct 2017 19:00:20 +0200 Subject: [PATCH] ELS Service Refactor: extract method to treat hits buckets --- dashboard/src/app/els.service.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) 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 {