diff --git a/src/app.module.ts b/src/app.module.ts index fea4f14a9d9e13647c838a11972aa368215fb907..30a7c066889c8f856501e0738da583943e1f9e62 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -27,6 +27,8 @@ import { ReplayModule } from './replay/replay.module'; TypeOrmModule checks ormconfig.json for database connection. + More information on global decorators can be found from shared folder. + Providers can be found from shared folder - HttpErrorFilter - LoggingInterceptor diff --git a/src/faction/faction.controller.ts b/src/faction/faction.controller.ts index 60ae33a221877101150967cc424aea3a4bf34360..24e4a9a588951bea93e7ca4e6aac5d6d5c0baee8 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -82,7 +82,7 @@ export class FactionController { // :id is the id of the game, and is needed for GameStates to check the state of the game @Put('join-faction/:id') @UseGuards(new AuthGuard()) - @GameStates('CREATED', 'STARTED') + @GameStates('CREATED', 'STARTED', 'PAUSED') @UsePipes(new ValidationPipe()) joinFaction( @User('id') person, diff --git a/src/main.ts b/src/main.ts index 2999e140b17ea0d80f29b37be40abf9f37dca1db..6504af39b7092ad0dc77890cba3b53abd22ef45f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,8 @@ import { AppModule } from './app.module'; /* Main.ts starts the server. + + .env.PORT is not defined, port 5000 will be listened by default */ async function bootstrap() { @@ -14,6 +16,6 @@ async function bootstrap() { // Cors is needed for application/json POST app.enableCors(); // Server will listen on port - await app.listen(port); + await app.listen(process.env.PORT || port); } bootstrap(); diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 9afb56d5bf638af1cf6877d1d2b30f1712fda910..6e3950936d5c1b8d83b468d3895b8bd91d45446c 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -18,8 +18,9 @@ UserController is being used for routing: - Register - Verify is checking for logged in user -*/ +See shared files for more information on decorators. +*/ @Controller('user') export class UserController { diff --git a/src/user/user.dto.ts b/src/user/user.dto.ts index c5bfa70cc3551645e1773e9aa7c4fb898b3f9887..4f1b8d624b09468a404bc4bc535880a93b3e6ce3 100644 --- a/src/user/user.dto.ts +++ b/src/user/user.dto.ts @@ -1,10 +1,18 @@ import { IsString, IsNotEmpty, Length } from 'class-validator'; +/* +Contains Validation for UserDTO +uses class-validator built in validations +see https://github.com/typestack/class-validator +*/ + export class UserDTO { - // uses class-validator built in validations - // see https://github.com/typestack/class-validator - @IsString() @IsNotEmpty() @Length(3, 31) - name: string; - @IsString() @IsNotEmpty() @Length(3, 255) - password: string; -} \ No newline at end of file + @IsString() + @IsNotEmpty() + @Length(3, 31) + name: string; + @IsString() + @IsNotEmpty() + @Length(3, 255) + password: string; +} diff --git a/src/user/user.entity.ts b/src/user/user.entity.ts index 716020ae49d675641863a1711e424b85dbd67608..216eeb838c49158bca3f7551886bc7e623265a62 100644 --- a/src/user/user.entity.ts +++ b/src/user/user.entity.ts @@ -11,6 +11,15 @@ import * as jwt from 'jsonwebtoken'; import { Game_PersonEntity } from '../game/game.entity'; import { Exclude } from 'class-transformer'; +/* +UserEntity reflects database table. + +Before handling password to database we encrypt it with bcrypt. +password field will be excluded unless we call repository relation. + +token will be created when user registers or logs in to the system. +*/ + @Entity('Person') export class PersonEntity { @PrimaryGeneratedColumn('uuid') id: string; @@ -39,6 +48,7 @@ export class PersonEntity { return await bcrypt.compareSync(attempt, this.password); } + // creates token from id and name, it will be created through jsonwebtoken and .env SECRET field private get token() { const { id, name } = this; return jwt.sign( diff --git a/src/user/user.module.ts b/src/user/user.module.ts index a160e47449b4d3724bfe4350f93569ae8e1073a4..8b01d8152f4682e5c17bd457e900caa74bada94e 100644 --- a/src/user/user.module.ts +++ b/src/user/user.module.ts @@ -3,13 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { UserController } from './user.controller'; import { UserService } from './user.service'; -import { PersonEntity} from './user.entity'; -import { GameEntity } from '../game/game.entity'; - +import { PersonEntity } from './user.entity'; /* Entities - PersonEntity -- GameEntity Controllers - UserController diff --git a/src/user/user.service.ts b/src/user/user.service.ts index e405972e9c1faf45d7796831b67266ae7f739870..d34dec06df7a8c6d742b26e77bd01cc9c2e73a21 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -5,9 +5,15 @@ import { InjectRepository } from '@nestjs/typeorm'; import { PersonEntity } from './user.entity'; import { UserDTO } from './user.dto'; /* -UserService contains -*/ +UserService contains functions for +- Login +- Register + +Both functions return logged in users tokenObject +See more info in UserEntity. +See more info on DTO in it's respective file +*/ @Injectable() export class UserService {