Skip to content
Snippets Groups Projects
Commit 21cbd659 authored by L4168's avatar L4168
Browse files

added path&service for modifying gamestate

parent cbcf068c
No related branches found
No related tags found
3 merge requests!59Development to master,!36Development,!32Game state
...@@ -14,9 +14,9 @@ import { ...@@ -14,9 +14,9 @@ import {
import { GameService } from './game.service'; import { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard'; import { AuthGuard } from '../shared/auth.guard';
import { User } from '../user/user.decorator'; import { User } from '../user/user.decorator';
import { GameDTO, FlagboxEventDTO } from './game.dto'; import { GameDTO, FlagboxEventDTO, GameStateDTO } from './game.dto';
import { ValidationPipe } from '../shared/validation.pipe'; import { ValidationPipe } from '../shared/validation.pipe';
import { Roles } from '../shared/roles.decorator'; import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity'; import { GameEntity } from './game.entity';
@Controller('game') @Controller('game')
...@@ -32,11 +32,19 @@ export class GameController { ...@@ -32,11 +32,19 @@ export class GameController {
@Put('edit/:id') @Put('edit/:id')
@Roles('admin') @Roles('admin')
@GameStates('CREATED')
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
async editGame(@Param('id') id: string, @Body() body: GameDTO) { async editGame(@Param('id') id: string, @Body() body: GameDTO) {
return this.gameservice.editGame(id, body); return this.gameservice.editGame(id, body);
} }
@Put('edit-state/:id')
@Roles('admin')
@UsePipes(new ValidationPipe())
async updateGameState(@Param('id') id: string, @Body() body: GameStateDTO) {
return this.gameservice.updateGameStatus(body);
}
@Get('listgames') @Get('listgames')
async listGames() { async listGames() {
return this.gameservice.listGames(); return this.gameservice.listGames();
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
ObjectivePointEntity, ObjectivePointEntity,
ObjectivePoint_HistoryEntity, ObjectivePoint_HistoryEntity,
} from './game.entity'; } from './game.entity';
import { GameDTO, FlagboxEventDTO } from './game.dto'; import { GameDTO, FlagboxEventDTO, GameStateDTO } from './game.dto';
import { PersonEntity } from '../user/user.entity'; import { PersonEntity } from '../user/user.entity';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { NotificationGateway } from '../notifications/notifications.gateway'; import { NotificationGateway } from '../notifications/notifications.gateway';
...@@ -39,6 +39,7 @@ export class GameService { ...@@ -39,6 +39,7 @@ export class GameService {
} }
// else add the game to the database // else add the game to the database
const game = await this.gameRepository.create(gameData); const game = await this.gameRepository.create(gameData);
game.state = 'CREATED';
await this.gameRepository.insert(game); await this.gameRepository.insert(game);
// add gamePerson with role admin to the game // add gamePerson with role admin to the game
const gamePerson = await this.game_PersonRepository.create({ const gamePerson = await this.game_PersonRepository.create({
...@@ -112,6 +113,17 @@ export class GameService { ...@@ -112,6 +113,17 @@ export class GameService {
}; };
} }
async updateGameStatus(game: GameStateDTO) {
const updatedGame = await this.gameRepository.create(game);
await this.gameRepository.save(updatedGame);
// notify players about game state change
this.notificationGateway.server.emit(game.id, 'event update');
return {
code: 200,
message: 'State was updated',
};
}
async listFactions(game: GameEntity) { async listFactions(game: GameEntity) {
return this.factionRepository.find({ game }); return this.factionRepository.find({ game });
} }
......
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