From bce14d94c58786ceeb03365d21d1322225190946 Mon Sep 17 00:00:00 2001 From: L4168 <L4168@student.jamk.fi> Date: Mon, 15 Jul 2019 14:36:17 +0300 Subject: [PATCH] promoting to admin nulls relation to faction and group --- src/faction/faction.service.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index 3681a94..bcaf4af 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -10,7 +10,6 @@ import { FactionDTO, } from './faction.dto'; import { Game_PersonEntity } from '../game/game.entity'; -import { async } from 'rxjs/internal/scheduler/async'; @Injectable() export class FactionService { @@ -82,9 +81,15 @@ export class FactionService { where: { gamepersonId }, }); if (gameperson) { - const factionleader = await this.game_PersonRepository.create(gameperson); - factionleader.role = body.role; - return await this.game_PersonRepository.save(factionleader); + const promotedPlayer = await this.game_PersonRepository.create( + gameperson, + ); + promotedPlayer.role = body.role; + if (body.role === 'admin') { + promotedPlayer.faction = null; + promotedPlayer.group = null; + } + return await this.game_PersonRepository.save(promotedPlayer); } throw new HttpException('player does not exist', HttpStatus.BAD_REQUEST); } -- GitLab