diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index 98fcc856d6a5e1cb469e81249eea044df4011877..7574d822c5aef8ef5c350ab349dc0801f916b753 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -88,4 +88,11 @@ export class FactionController { ) { return this.factionservice.joinFaction(person, data); } + + // check if person belongs to a faction in a game + @Get('check-faction/:id') + @UseGuards(new AuthGuard()) + checkFaction(@User('id') userId, @Param('id') gameId) { + return this.factionservice.verifyUser(userId, gameId); + } } diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index 76242dfe1bceda0776435b43c4fdc4cb60fe272c..e6bec65d77e45e500aad4c49f1e5f7a6168e53c4 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -129,4 +129,19 @@ export class FactionService { }); return members; } + + async verifyUser(person, game) { + const gameperson = await this.game_PersonRepository.findOne({ + where: { person, game }, + relations: ['faction'], + }); + if (gameperson) { + return { + code: 200, + message: gameperson, + }; + } else { + throw new HttpException('No faction was found', HttpStatus.BAD_REQUEST); + } + } }