From 063d7e984c923117e030fb53dff80840af861e1b Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Fri, 19 Jul 2019 14:24:52 +0300
Subject: [PATCH] replay returns drawings and gamedata

---
 src/replay/replay.service.ts | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/replay/replay.service.ts b/src/replay/replay.service.ts
index 04ace74..c779437 100644
--- a/src/replay/replay.service.ts
+++ b/src/replay/replay.service.ts
@@ -56,6 +56,14 @@ export class ReplayService {
   } */
 
   async replayData(gameId) {
+    //
+    // this block returns game's initial location
+    //
+    let gameObj = await this.gameRepository.findOne({
+      where: { id: gameId },
+      select: ['center'],
+    });
+    let gamelocation = [gameObj.center.lat, gameObj.center.lng];
     //
     // this block returns all player data from the game
     //
@@ -111,11 +119,28 @@ export class ReplayService {
         );
       }),
     );
+    //
+    // this block returns all map drawings from the game
+    //
+    let refs = await this.mapdrawingRepository.find({
+      where: { gameId: gameId },
+      select: ['mapDrawingId'],
+    });
+
+    let drawData = await Promise.all(
+      refs.map(async ref => {
+        return await this.mapHistoryRepository.find({
+          where: { mapdrawing: ref.mapDrawingId },
+        });
+      }),
+    );
 
     return {
+      location: gamelocation,
       players: currentdata,
       factions: currentFactions,
       scores: currentScore,
+      drawings: drawData,
     };
   }
   // generate mockdata for a 3 day game
-- 
GitLab