From 74e4d57a0a2a9fed84ad3a9d8dc73e876bfca077 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marko=20Syd=C3=A4nmaa?= <L4072@student.jamk.fi>
Date: Wed, 24 Jul 2019 11:35:08 +0300
Subject: [PATCH] auditing backend

---
 src/app.module.ts           | 13 +++++++++++++
 src/main.ts                 |  6 +++++-
 src/user/user.controller.ts |  9 +++++++++
 src/user/user.module.ts     | 14 +++++++++++++-
 src/user/user.service.ts    | 29 ++++-------------------------
 5 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/src/app.module.ts b/src/app.module.ts
index 53a56f4..fea4f14 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -21,6 +21,19 @@ import { GameModule } from './game/game.module';
 import { ScoreModule } from './score/score.module';
 import { ReplayModule } from './replay/replay.module';
 
+/*
+  Core of the server,
+  Every module is being imported and combined here.
+
+  TypeOrmModule checks ormconfig.json for database connection.
+
+  Providers can be found from shared folder
+   - HttpErrorFilter
+   - LoggingInterceptor
+   - RolesGuard Decorator
+   - StatesGuard Decorator
+*/
+
 @Module({
   imports: [
     TypeOrmModule.forRoot(),
diff --git a/src/main.ts b/src/main.ts
index ebd53e5..2999e14 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -7,9 +7,13 @@ import { AppModule } from './app.module';
 */
 
 async function bootstrap() {
+  // port opened
+  const port = 5000;
+
   const app = await NestFactory.create(AppModule);
   // Cors is needed for application/json POST
   app.enableCors();
-  await app.listen(5000);
+  // Server will listen on port
+  await app.listen(port);
 }
 bootstrap();
diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts
index 4d4158d..9afb56d 100644
--- a/src/user/user.controller.ts
+++ b/src/user/user.controller.ts
@@ -12,6 +12,15 @@ import { UserDTO } from './user.dto';
 import { AuthGuard } from '../shared/auth.guard';
 import { ValidationPipe } from '../shared/validation.pipe';
 
+/*
+UserController is being used for routing:
+- Login
+- Register
+
+- Verify is checking for logged in user
+*/
+
+
 @Controller('user')
 export class UserController {
   constructor(private userService: UserService) {}
diff --git a/src/user/user.module.ts b/src/user/user.module.ts
index 6cb77a7..a160e47 100644
--- a/src/user/user.module.ts
+++ b/src/user/user.module.ts
@@ -6,8 +6,20 @@ import { UserService } from './user.service';
 import { PersonEntity} from './user.entity';
 import { GameEntity } from '../game/game.entity';
 
+/*
+Entities
+- PersonEntity
+- GameEntity
+
+Controllers
+- UserController
+
+Provider
+- UserService
+*/
+
 @Module({
-  imports: [TypeOrmModule.forFeature([PersonEntity, GameEntity])],
+  imports: [TypeOrmModule.forFeature([PersonEntity])],
   controllers: [UserController],
   providers: [UserService],
 })
diff --git a/src/user/user.service.ts b/src/user/user.service.ts
index aa511e2..e405972 100644
--- a/src/user/user.service.ts
+++ b/src/user/user.service.ts
@@ -4,16 +4,16 @@ import { InjectRepository } from '@nestjs/typeorm';
 
 import { PersonEntity } from './user.entity';
 import { UserDTO } from './user.dto';
-import { GameEntity } from '../game/game.entity';
-import { GameDTO } from '../game/game.dto';
+/*
+UserService contains 
+*/
+
 
 @Injectable()
 export class UserService {
   constructor(
     @InjectRepository(PersonEntity)
     private userRepository: Repository<PersonEntity>,
-    @InjectRepository(GameEntity)
-    private gameRepository: Repository<GameEntity>,
   ) {}
 
   async register(data: UserDTO) {
@@ -38,25 +38,4 @@ export class UserService {
     }
     return user.tokenObject();
   }
-
-  // liitytään peliin
-  async joinGame(game: GameDTO, data: UserDTO) {
-    try {
-      // etsi peli valinnan mukaan ja otetaan käyttäjän rooli kyseisestä pelistä talteen
-      const role = await this.gameRepository.findOne();
-      return role;
-    } catch (error) {
-      return error.message;
-    }
-  }
-
-  // liitytään factionii
-  async joinFaction(game: GameDTO, data: UserDTO): Promise<boolean> {
-    try {
-      // tarkistetaan factionin salasana
-      return true;
-    } catch (error) {
-      return error;
-    }
-  }
 }
-- 
GitLab