From c5a17c37bd3f370257ff7ae2de833996dfaa9eae Mon Sep 17 00:00:00 2001
From: L4168 <L4168@student.jamk.fi>
Date: Fri, 5 Jul 2019 13:49:17 +0300
Subject: [PATCH] added path&service for verifying faction

---
 src/faction/faction.controller.ts |  7 +++++++
 src/faction/faction.service.ts    | 15 +++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts
index 98fcc85..7574d82 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 76242df..e6bec65 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);
+    }
+  }
 }
-- 
GitLab