From 60d7e75cdc898f6aa09b6fe05e34b08079bded15 Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Fri, 7 Jun 2019 15:39:46 +0300
Subject: [PATCH] fixed imports

---
 src/game/game.controller.ts |  1 -
 src/game/game.dto.ts        |  2 +-
 src/game/game.entity.ts     |  2 +-
 src/game/game.module.ts     |  5 +++--
 src/game/game.service.ts    | 22 ++++++++++++++++++----
 5 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts
index ed3bef3..99a7bfe 100644
--- a/src/game/game.controller.ts
+++ b/src/game/game.controller.ts
@@ -5,7 +5,6 @@ import { AuthGuard } from '../shared/auth.guard';
 import { User } from '../user/user.decorator';
 import { GameDTO } from './game.dto';
 import { ValidationPipe } from '../shared/validation.pipe';
-import { async } from 'rxjs/internal/scheduler/async';
 
 @Controller('game')
 export class GameController {
diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts
index 5a41f38..b4607e3 100644
--- a/src/game/game.dto.ts
+++ b/src/game/game.dto.ts
@@ -36,7 +36,7 @@ export class GameDTO {
   })
   // custom validation for array length (arr>min, arr<max)
   @Validate(ArrayLength, [4, 8])
-  passwords: [];
+  passwords: string[];
   factions: FactionDTO[];
 }
 
diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts
index c4008f7..af046da 100644
--- a/src/game/game.entity.ts
+++ b/src/game/game.entity.ts
@@ -17,7 +17,7 @@ export class GameEntity {
   @Column('json') map: JSON;
   @Column('timestamp') startdate: Timestamp;
   @Column('timestamp') enddate: Timestamp;
-  @Column("text", {array: true}) passwords: [];
+  @Column("text", {array: true}) passwords: string[];
   @OneToMany(type => FactionEntity, faction => faction.game)
   factions: FactionEntity[];
   @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
diff --git a/src/game/game.module.ts b/src/game/game.module.ts
index b24a829..e6a23cf 100644
--- a/src/game/game.module.ts
+++ b/src/game/game.module.ts
@@ -3,10 +3,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';
 
 import { GameController } from './game.controller';
 import { GameService } from './game.service';
-import { GameEntity, FactionEntity } from './game.entity';
+import { GameEntity, FactionEntity, Game_PersonEntity } from './game.entity';
+import { PersonEntity } from 'src/user/user.entity';
 
 @Module({
-  imports: [TypeOrmModule.forFeature([GameEntity, FactionEntity])],
+  imports: [TypeOrmModule.forFeature([GameEntity, FactionEntity, Game_PersonEntity, PersonEntity])],
   controllers: [GameController],
   providers: [GameService]
 })
diff --git a/src/game/game.service.ts b/src/game/game.service.ts
index 5c5fca0..87ec5c4 100644
--- a/src/game/game.service.ts
+++ b/src/game/game.service.ts
@@ -2,9 +2,9 @@ import { Injectable, Logger, HttpException, HttpStatus } from '@nestjs/common';
 import { InjectRepository } from '@nestjs/typeorm';
 import { Repository, In } from 'typeorm';
 
-import { GameEntity, FactionEntity } from './game.entity';
+import { GameEntity, FactionEntity, Game_PersonEntity } from './game.entity';
 import { GameDTO } from './game.dto';
-import { PersonEntity } from 'src/user/user.entity';
+import { PersonEntity } from '../user/user.entity';
 
 @Injectable()
 export class GameService {
@@ -15,6 +15,8 @@ export class GameService {
     private factionRepository: Repository<FactionEntity>,
     @InjectRepository(PersonEntity)
     private personRepository: Repository<PersonEntity>,
+    @InjectRepository(Game_PersonEntity)
+    private game_PersonRepository: Repository<Game_PersonEntity>,
   ) {}
 
   // create a new game
@@ -46,9 +48,21 @@ export class GameService {
   }
 
   // checks the password, creates an entry in GamePerson table with associated role&faction
-  async joinGame(person, gameId, password) {
-    const user = await this.personRepository.findOne({ where: { id: person.id } });
+  async joinGame(person, gameId, json) {
+    const user = await this.personRepository.findOne({
+      where: { id: person },
+    });
     const game = await this.gameRepository.findOne({ where: { id: gameId } });
+
+    const index = game.passwords.indexOf(json.password);
+
+    // create game_Person entry
+/*     const gamePerson = await this.game_PersonRepository.create({
+      faction,
+      gameId,
+      person,
+    });
+    */
     return 'WIP';
   }
 
-- 
GitLab