Skip to content
Snippets Groups Projects
Commit 05025de6 authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

faction auditted

parent aba25a45
No related branches found
No related tags found
2 merge requests!59Development to master,!58Development to testing
......@@ -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
......
......@@ -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')
......
......@@ -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')
......
......@@ -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;
}
......
......@@ -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([
......
......@@ -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({
......
......@@ -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);
}
......
......@@ -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')
......
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;
});
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment