diff --git a/src/app.module.ts b/src/app.module.ts index 30a7c066889c8f856501e0738da583943e1f9e62..571d9240e67c2f34fc52785f793f43b86bc78730 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -25,10 +25,12 @@ import { ReplayModule } from './replay/replay.module'; Core of the server, Every module is being imported and combined here. + AppController needs to be kept in for SSL verification to work (root needs to return something) + 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 24e4a9a588951bea93e7ca4e6aac5d6d5c0baee8..cbbd3ecf587d0a29805f3758b8d4adb36444577a 100644 --- a/src/faction/faction.controller.ts +++ b/src/faction/faction.controller.ts @@ -7,8 +7,6 @@ import { Body, Get, Put, - UseInterceptors, - ClassSerializerInterceptor, Delete, } from '@nestjs/common'; @@ -26,6 +24,23 @@ import { FactionService } from './faction.service'; import { Roles, GameStates } from '../shared/guard.decorator'; import { GamePerson } from 'src/game/gameperson.decorator'; +/* +FactionController is being used for routing: + +Group +- create group when game status is CREATED +- getting groups with faction id(this is used mainly for listing players) +- joining group when game status is CREATED + +Faction +- checking users faction +- joining faction +- leaving faction +- changing faction multiplier (not implemented) + +See shared folder files for more information on decorators. +*/ + @Controller('faction') export class FactionController { constructor(private factionservice: FactionService) {} @@ -40,9 +55,7 @@ export class FactionController { @Param('id') id: string, @Body() data: GameGroupDTO, ) { - try { - return this.factionservice.createGroup(person, id, data); - } catch (error) {} + return this.factionservice.createGroup(person, id, data); } // id is faction ID @@ -63,12 +76,6 @@ export class FactionController { return this.factionservice.joinGroup(gameperson, data); } - @UseInterceptors(ClassSerializerInterceptor) - @Get('get-faction-members/:id') - async getFactionMembers(@Param('id') factionId) { - return this.factionservice.listFactionMembers(factionId); - } - // param game ID is passed to @Roles @Put('promote/:id') @Roles('admin') @@ -100,13 +107,15 @@ export class FactionController { leaveFaction(@GamePerson('gamepersonId') gamepersonId) { return this.factionservice.leaveFaction(gamepersonId); } + // used to change factions multiplier - @Put('faction-multiplier/:id') - @Roles('admin') - @GameStates('STARTED') - factionMultiplier(@Param('id') game, @Body() body: FactionDTO) { - return this.factionservice.changeFactionMultiplier(body); - } + // not implemented in frontend uncomment this and services equivalent when needed + // @Put('faction-multiplier/:id') + // @Roles('admin') + // @GameStates('STARTED') + // factionMultiplier(@Param('id') game, @Body() body: FactionDTO) { + // return this.factionservice.changeFactionMultiplier(body); + // } // check if person belongs to a faction in a game @Get('check-faction/:id') diff --git a/src/faction/faction.dto.ts b/src/faction/faction.dto.ts index fbc46d3267dc109010c4450a371ede7300c0d1d0..df69715283e4de46cdf7d09e4ac657fbb81a1d68 100644 --- a/src/faction/faction.dto.ts +++ b/src/faction/faction.dto.ts @@ -13,10 +13,17 @@ import { } from 'class-validator'; import { GameEntity } from '../game/game.entity'; -import { RoleValidation, Uuid } from '../shared/custom-validation'; +import { RoleValidation } from '../shared/custom-validation'; import { GameDTO } from '../game/game.dto'; import { FactionEntity, GameGroupEntity } from './faction.entity'; +/* +Contains Validation for FactionDTO, JoinFactionDTO, PromotePlayerDTO, GameGroupDTO, JoinGameGroupDTO + +uses class-validator built in validations +see https://github.com/typestack/class-validator +*/ + export class FactionDTO { @IsOptional() @IsUUID('4') diff --git a/src/faction/faction.entity.ts b/src/faction/faction.entity.ts index a851e190b349d046aae00c776aef345b7de6f373..0240260a036d0c832f40ba4be8e4d6de8ce4c19e 100644 --- a/src/faction/faction.entity.ts +++ b/src/faction/faction.entity.ts @@ -12,11 +12,11 @@ import { GameEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity'; import { MapDrawingEntity } from '../draw/coordinate.entity'; import { Exclude } from 'class-transformer'; -import { ScoreEntity } from 'src/score/score.entity'; +import { ScoreEntity } from '../score/score.entity'; -////////////////////////////////////////////////////////////////////// -/// Entities for Factions and Groups in Factions /// -////////////////////////////////////////////////////////////////////// +/* +FactionEntity & GameGroupEntity reflect database tables. +*/ @Entity('Faction') export class FactionEntity { @@ -44,11 +44,6 @@ export class FactionEntity { }) scores: ScoreEntity[]; - factionObject() { - const { factionId, factionName, game } = this; - return { factionId, factionName, game }; - } - passwordCheck(pass: string) { return pass == this.factionPassword ? true : false; } diff --git a/src/faction/faction.module.ts b/src/faction/faction.module.ts index f53f076b7e88af7536e6307640d7e10414a7c357..49ba6e916252a77eaa957a57995d0076d7303bfb 100644 --- a/src/faction/faction.module.ts +++ b/src/faction/faction.module.ts @@ -6,10 +6,19 @@ import { FactionService } from './faction.service'; import { GameGroupEntity, FactionEntity } from './faction.entity'; import { Game_PersonEntity } from '../game/game.entity'; -///////////////////////////////////////////////////////////////////// -/// Faction /// -/// - contains everything to do with Faction data. /// -///////////////////////////////////////////////////////////////////// +/* +Entities +- FactionEntity +- Game_PersonEntity +- GameGroupEntity + +Controllers +- FactionController + +Provider +- FactionService +*/ + @Module({ imports: [ TypeOrmModule.forFeature([ diff --git a/src/faction/faction.service.ts b/src/faction/faction.service.ts index 3e2efca3c2c6e6c275dbe76e5b8006559f2009fb..a3ea83ebefb7b34e2bb83fa714a1b0b7817acb8a 100644 --- a/src/faction/faction.service.ts +++ b/src/faction/faction.service.ts @@ -11,6 +11,21 @@ import { } from './faction.dto'; import { Game_PersonEntity } from '../game/game.entity'; +/* +FactionService contains functions for +- Joining faction +- Leaving faction +- Change faction multiplier (not implemented) + +Group +- Creating group +- List faction players in groups + +Player +- Promote player +- verifying user +*/ + @Injectable() export class FactionService { constructor( @@ -67,13 +82,13 @@ export class FactionService { } // changes factions multiplier to the value given to FactionDTO - async changeFactionMultiplier(body: FactionDTO) { - const faction = await this.factionRepository.findOne({ - where: { factionId: body.factionId }, - }); - faction.multiplier = body.multiplier; - return await this.factionRepository.save(faction); - } + // async changeFactionMultiplier(body: FactionDTO) { + // const faction = await this.factionRepository.findOne({ + // where: { factionId: body.factionId }, + // }); + // faction.multiplier = body.multiplier; + // return await this.factionRepository.save(faction); + // } async promotePlayer(body) { const gamepersonId = body.player; @@ -197,18 +212,6 @@ export class FactionService { }; } - // lists all members from given faction - async listFactionMembers(faction) { - const members = await this.game_PersonRepository.find({ - where: { faction }, - relations: ['person'], - }); - members.sort(function(a, b) { - return a['person']['name'].localeCompare(b['person']['name']); - }); - return members; - } - // checks if player is in a faction and what role the player is in async verifyUser(person, game) { const gameperson = await this.game_PersonRepository.findOne({ diff --git a/src/score/score.controller.ts b/src/score/score.controller.ts index a9989a06b77d8ec08b1c84db9dbf24ad87fe9377..344c33c02a84f1e49b202090dffedb0d42d23ce8 100644 --- a/src/score/score.controller.ts +++ b/src/score/score.controller.ts @@ -32,7 +32,6 @@ export class ScoreController { // shows scores, :id is gameId @Get('get-score/:id') @UseInterceptors(ClassSerializerInterceptor) - @GameStates('STARTED') async getScores(@Param('id') gameId: GameEntity) { return this.scoreService.getScores(gameId); } diff --git a/src/user/user.controller.ts b/src/user/user.controller.ts index 6e3950936d5c1b8d83b468d3895b8bd91d45446c..09e308de29765af603b07335007d85ffcfa953c7 100644 --- a/src/user/user.controller.ts +++ b/src/user/user.controller.ts @@ -19,7 +19,7 @@ UserController is being used for routing: - Verify is checking for logged in user -See shared files for more information on decorators. +See shared folder files for more information on decorators. */ @Controller('user') diff --git a/src/user/user.decorator.ts b/src/user/user.decorator.ts index 2c499d904927d0502567fc2131270b81170327f4..2f9a6fc9ab06820e547670336872ac2dbcf32d08 100644 --- a/src/user/user.decorator.ts +++ b/src/user/user.decorator.ts @@ -1,6 +1,14 @@ -import { createParamDecorator } from "@nestjs/common"; +import { createParamDecorator } from '@nestjs/common'; + +/* +UserDecorator + +See auth.guard.ts in shared folder for more information + +Returns user id and user name, this is mainly used to return user id +*/ // used to pass user information to controllers export const User = createParamDecorator((data, req) => { - return data ? req.user[data] : req.user; -}) \ No newline at end of file + return data ? req.user[data] : req.user; +}); diff --git a/src/user/user.module.ts b/src/user/user.module.ts index 8b01d8152f4682e5c17bd457e900caa74bada94e..7216dde2423e5d5aac5817a098c946353aeec315 100644 --- a/src/user/user.module.ts +++ b/src/user/user.module.ts @@ -4,6 +4,7 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { UserController } from './user.controller'; import { UserService } from './user.service'; import { PersonEntity } from './user.entity'; + /* Entities - PersonEntity