diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 84a8a97a30b53b094912d153ec9736c3fed1e59b..e4288a40a2237882742a0cb059984cd62a8b966b 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -1,4 +1,4 @@ -import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; +import { Injectable, HttpException, HttpStatus, Inject } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository, Not } from 'typeorm'; @@ -30,7 +30,6 @@ export class GameService { >, private notificationGateway: NotificationGateway, ) {} - // create a new game async createNewGame(personId: PersonEntity, gameData: GameDTO) { // checks if a game with the same name exists already diff --git a/src/main.ts b/src/main.ts index ebd53e5906d44738a4775716b7165108fae426ca..dec8e6ff6f5d37f0373c9b7b709b717212408500 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,7 @@ import { AppModule } from './app.module'; */ async function bootstrap() { - const app = await NestFactory.create(AppModule); + const app = await NestFactory.create(AppModule, { logger: console }); // Cors is needed for application/json POST app.enableCors(); await app.listen(5000); diff --git a/src/score/score.service.ts b/src/score/score.service.ts index 90716c4b2e9f5d72f21971edb574972a2ccfda6d..1a62576004559e371595916d01f94014c4aeeef9 100644 --- a/src/score/score.service.ts +++ b/src/score/score.service.ts @@ -1,4 +1,10 @@ -import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; +import { + Injectable, + HttpException, + HttpStatus, + Logger, + OnModuleInit, +} from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; @@ -24,7 +30,10 @@ export class ScoreService { @InjectRepository(FactionEntity) private factionRepository: Repository<FactionEntity>, private notificationGateway: NotificationGateway, - ) {} + ) { + // initialize timer when service is loaded + this.startTimer(); + } async addScore(scoreData: ScoreDTO, gameId: GameEntity) { // check if faction exists @@ -110,10 +119,32 @@ export class ScoreService { ); return scores; } -} // -// Hae kaikki Objective pointit -// aja map funktio pelin objective pointteihin -// jokaisella objective point ID:llä hae historystä -// relaatio, missä uusin timestamp -// katso uusimmista history entrystä omistaja + // tickinterval in milliseconds (10 minutes = 600 000) + private readonly tickInterval: number = 5000; + // dictionary to push gameId linked to start state + private ongoingGames = {}; + + // initializing timer + async startTimer() { + setInterval(this.Tick, this.tickInterval); + } + + async addToTimer(gameId: string) { + this.Tick(); + this.ongoingGames[gameId] = Date.now(); + } + + async removeFromTimer(gameId: string) { + delete this.ongoingGames[gameId]; + } + + // tick score for games with STARTED-status + Tick = () => { + if (this.ongoingGames != null) { + for (var game in this.ongoingGames) { + console.log(game); + } + } + }; +}