From 7cfed59c5853e18358e68b767714960384e6bd33 Mon Sep 17 00:00:00 2001
From: Samuli Virtapohja <l4721@student.jamk.fi>
Date: Wed, 24 Jul 2019 13:53:12 +0300
Subject: [PATCH] add games with started state to ticks

---
 src/game/tick.service.ts | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/game/tick.service.ts b/src/game/tick.service.ts
index a12c452..b6ba273 100644
--- a/src/game/tick.service.ts
+++ b/src/game/tick.service.ts
@@ -1,9 +1,13 @@
 import { Injectable, Logger } from '@nestjs/common';
 import { ScoreService } from '../score/score.service';
+import { GameService } from './game.service';
 
 @Injectable()
 export class TickService {
-  constructor(private scoreService: ScoreService) {
+  constructor(
+    private scoreService: ScoreService,
+    private gameService: GameService,
+  ) {
     // whenever Tickservice is called, it will start ticktimer
     /* 
     WARNING: multiple calls start multiple timers, 
@@ -21,6 +25,14 @@ export class TickService {
   async startTimer() {
     this.logger.log('Started timer');
     setInterval(this.Tick, this.tickInterval);
+
+    // get games with STARTED value
+    let games = await this.gameService.listGames('STARTED');
+
+    // add STARTED games to dictionary
+    games.map(game => {
+      this.ongoingGames[game.id] = Date.now();
+    });
   }
 
   // add the game to tick queue
-- 
GitLab