From 4a16057a683f4db0984b82080cd458c74d27542b Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Thu, 18 Jul 2019 16:29:32 +0300
Subject: [PATCH] format score return for replay

---
 src/replay/replay.service.ts | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/replay/replay.service.ts b/src/replay/replay.service.ts
index 43fc0ab..3120ecd 100644
--- a/src/replay/replay.service.ts
+++ b/src/replay/replay.service.ts
@@ -93,17 +93,25 @@ export class ReplayService {
     //
     // this block returns all score data from the game
     //
-    let scores = await this.scoreRepository.find({
-      where: { faction: In(factionIds) },
-      relations: ['faction'],
-    });
-    let currentScore = scores.map(score => {
-      return {
-        score: score.score,
-        timestamp: score.scoreTimeStamp,
-        faction: score.faction['factionName'],
-      };
-    });
+    let currentScore = [];
+    await Promise.all(
+      factions.map(async faction => {
+        let scores = await this.scoreRepository.find({
+          where: { faction: faction },
+          relations: ['faction'],
+        });
+        currentScore.push(
+          scores.map(score => {
+            return {
+              score: score.score,
+              timestamp: score.scoreTimeStamp,
+              faction: score.faction['factionName'],
+            };
+          }),
+        );
+      }),
+    );
+    console.log(currentScore);
 
     return {
       players: currentdata,
-- 
GitLab