diff --git a/src/game/game.service.ts b/src/game/game.service.ts index dc1d92982afc59066f31f16e3153e7361e75aead..6292d54bffcb6749c5fac3d7070e7bca0ddc373c 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -8,7 +8,7 @@ import { ObjectivePointEntity, ObjectivePoint_HistoryEntity, } from './game.entity'; -import { GameDTO, FlagboxEventDTO } from './game.dto'; +import { GameDTO, FlagboxEventDTO, GameGroupDTO } from './game.dto'; import { PersonEntity } from '../user/user.entity'; import { GameGroupEntity } from './group.entity'; import { FactionEntity } from './faction.entity'; @@ -39,22 +39,18 @@ export class GameService { // create a new game async createNewGame(personId: PersonEntity, gameData: GameDTO) { // checks if a game with the same name exists already - const { name } = gameData; - if (await this.gameRepository.findOne({ where: { name } })) { + if (await this.gameRepository.findOne({ name: gameData.name })) { throw new HttpException('Game already exists', HttpStatus.BAD_REQUEST); } // else add the game to the database - const game = await this.gameRepository.create({ - ...gameData, - factions: gameData.factions, - }); + const game = await this.gameRepository.create(gameData); await this.gameRepository.insert(game); + // add gamePerson with role admin to the game const gamePerson = await this.game_PersonRepository.create({ - faction: null, game: game, person: personId, + role: 'admin', }); - gamePerson['role'] = 'admin'; await this.game_PersonRepository.insert(gamePerson); return { message: 'New game added', @@ -64,16 +60,13 @@ export class GameService { // edit already created game async editGame(id: string, gameData: GameDTO) { // checks if a game with the same name exists already - const { name } = gameData; - if (await this.gameRepository.findOne({ name: name, id: Not(id) })) { + if ( + await this.gameRepository.findOne({ name: gameData.name, id: Not(id) }) + ) { throw new HttpException('Game already exists', HttpStatus.BAD_REQUEST); } // update game entry in db - const updatedGame = await this.gameRepository.create({ - ...gameData, - factions: null, - objective_points: null, - }); + const updatedGame = await this.gameRepository.create(gameData); updatedGame['id'] = id; const gameId = await this.gameRepository.save(updatedGame); @@ -131,7 +124,7 @@ export class GameService { } // checks the password, creates an entry in GamePerson table with associated role&faction - async createGroup(person, gameId, groupData) { + async createGroup(person, gameId, groupData: GameGroupDTO) { // check if the person already is in a group in this game const checkDuplicate = await this.game_PersonRepository.findOne({ person: person, @@ -280,3 +273,4 @@ export class GameService { } } } + \ No newline at end of file