diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index ed3bef3e22f0d027faacb9d1f499fd5a621ea7cb..99a7bfe8e8e6dd9f121b05714359d2060b5f3712 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 5a41f380038398173fae050bf086c83406816502..b4607e3aee2d5c057d861c4e1f8a4acec04af3bc 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 c4008f763bbeeac20565859f2d3ac0f849dd5d85..af046da66db9160ae67720b9884ac2c54eb1c705 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 b24a8293cd4b13e7820adc8b280c6740cf2f6c1b..e6a23cfabcf9fc4d8ed5d230e272ffe44448b025 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 5c5fca059567c0d974b0cdf9d3a46047802ff94f..87ec5c4f5afc4f252329c4a70ba3b89511335439 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'; }