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

game folder audited

parent c522aefc
No related branches found
No related tags found
2 merge requests!59Development to master,!58Development to testing
...@@ -41,9 +41,11 @@ export class GameController { ...@@ -41,9 +41,11 @@ export class GameController {
private gameservice: GameService, private gameservice: GameService,
private tickservice: TickService, private tickservice: TickService,
) { ) {
// starts timer
this.tickservice.startTimer(); this.tickservice.startTimer();
} }
//new game
@Post('new') @Post('new')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
...@@ -51,6 +53,7 @@ export class GameController { ...@@ -51,6 +53,7 @@ export class GameController {
return this.gameservice.createNewGame(person, body); return this.gameservice.createNewGame(person, body);
} }
// edit game
@Put('edit/:id') @Put('edit/:id')
@Roles('admin') @Roles('admin')
@GameStates('CREATED') @GameStates('CREATED')
...@@ -60,6 +63,7 @@ export class GameController { ...@@ -60,6 +63,7 @@ export class GameController {
return this.gameservice.editGame(id, body); return this.gameservice.editGame(id, body);
} }
// delete game
@Delete('delete/:id') @Delete('delete/:id')
@Roles('admin') @Roles('admin')
@GameStates('CREATED') @GameStates('CREATED')
...@@ -67,6 +71,7 @@ export class GameController { ...@@ -67,6 +71,7 @@ export class GameController {
return this.gameservice.deleteGame(id); return this.gameservice.deleteGame(id);
} }
// change game state
@Put('edit-state/:id') @Put('edit-state/:id')
@Roles('admin') @Roles('admin')
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
...@@ -74,11 +79,13 @@ export class GameController { ...@@ -74,11 +79,13 @@ export class GameController {
return this.gameservice.updateGameStatus(body); return this.gameservice.updateGameStatus(body);
} }
// list all games
@Get('listgames') @Get('listgames')
async listGames(state) { async listGames(state) {
return this.gameservice.listGames(state); return this.gameservice.listGames(state);
} }
// list games based on parameter
@Get('listgames/:state') @Get('listgames/:state')
async listGamesState(@Param('state') state: string) { async listGamesState(@Param('state') state: string) {
return this.gameservice.listGames(state); return this.gameservice.listGames(state);
...@@ -91,28 +98,33 @@ export class GameController { ...@@ -91,28 +98,33 @@ export class GameController {
return this.gameservice.returnGameInfo(id); return this.gameservice.returnGameInfo(id);
} }
//get all factions
@Get('get-factions/:id') @Get('get-factions/:id')
@Roles('admin') @Roles('admin')
async returnGameFactions(@Param('id') id: GameEntity) { async returnGameFactions(@Param('id') id: GameEntity) {
return this.gameservice.listFactions(id); return this.gameservice.listFactions(id);
} }
// get flagbox events
@Get('flag-events/:id') @Get('flag-events/:id')
async returnFlagboxInfo(@Param('id') id: GameEntity) { async returnFlagboxInfo(@Param('id') id: GameEntity) {
return this.gameservice.returnObjectivePointInfo(id); return this.gameservice.returnObjectivePointInfo(id);
} }
// initial settings for flagbox
@Get('flag/:id') @Get('flag/:id')
async flagboxQuery(@Param('id') id: string) { async flagboxQuery(@Param('id') id: string) {
return this.gameservice.flagboxQuery(id); return this.gameservice.flagboxQuery(id);
} }
// flagbox event
@Post('flag/:id') @Post('flag/:id')
@GameStates('STARTED') @GameStates('STARTED')
async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) { async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) {
return this.gameservice.flagboxEvent(id, data); return this.gameservice.flagboxEvent(id, data);
} }
// image upload
@Post('upload') @Post('upload')
@UseInterceptors( @UseInterceptors(
FileInterceptor('image', { FileInterceptor('image', {
...@@ -134,6 +146,7 @@ export class GameController { ...@@ -134,6 +146,7 @@ export class GameController {
return image; return image;
} }
// get images
@Get('images/:img') @Get('images/:img')
returnImage(@Param('img') image, @Res() res) { returnImage(@Param('img') image, @Res() res) {
return res.sendFile(image, { root: 'images' }); return res.sendFile(image, { root: 'images' });
......
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
Length, Length,
IsDateString, IsDateString,
IsNumber, IsNumber,
Validate,
Min, Min,
Max, Max,
ValidateNested, ValidateNested,
...@@ -15,7 +14,6 @@ import { ...@@ -15,7 +14,6 @@ import {
} from 'class-validator'; } from 'class-validator';
import { ObjectivePointEntity } from './game.entity'; import { ObjectivePointEntity } from './game.entity';
import { CenterJSON } from '../shared/custom-validation';
import { FactionDTO } from '../faction/faction.dto'; import { FactionDTO } from '../faction/faction.dto';
import { CenterDTO, NodeSettingsDTO } from './game.json.dto'; import { CenterDTO, NodeSettingsDTO } from './game.json.dto';
import { Type } from 'class-transformer'; import { Type } from 'class-transformer';
......
import { Injectable, HttpException, HttpStatus, Inject } from '@nestjs/common'; import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository, Not } from 'typeorm'; import { Repository, Not } from 'typeorm';
...@@ -162,7 +162,6 @@ export class GameService { ...@@ -162,7 +162,6 @@ export class GameService {
const updatedGame = await this.gameRepository.findOne({ id: game.id }); const updatedGame = await this.gameRepository.findOne({ id: game.id });
if (updatedGame) { if (updatedGame) {
updatedGame.state = game.state; updatedGame.state = game.state;
console.log(game.state);
await this.gameRepository.save(updatedGame); await this.gameRepository.save(updatedGame);
//add or remove from scoretick based on gamestate //add or remove from scoretick based on gamestate
...@@ -188,7 +187,7 @@ export class GameService { ...@@ -188,7 +187,7 @@ export class GameService {
} }
async deleteGame(id) { async deleteGame(id) {
// TODO: Delete factions from Faction table associated with the deleted game // Delete factions from Faction table associated with the deleted game
await this.gameRepository.delete({ id }); await this.gameRepository.delete({ id });
return { return {
message: 'Game deleted', message: 'Game deleted',
...@@ -270,6 +269,7 @@ export class GameService { ...@@ -270,6 +269,7 @@ export class GameService {
return response; return response;
} }
//returns flagbox colour and faction
private async infoHelper(obj) { private async infoHelper(obj) {
return (await obj) return (await obj)
? { ? {
......
...@@ -7,6 +7,8 @@ import { createParamDecorator } from '@nestjs/common'; ...@@ -7,6 +7,8 @@ import { createParamDecorator } from '@nestjs/common';
role role
faction faction
} }
See more information from decorators in shared folder files.
*/ */
export const GamePerson = createParamDecorator((data, req) => { export const GamePerson = createParamDecorator((data, req) => {
return data ? req.gameperson[data] : req.gameperson; return data ? req.gameperson[data] : req.gameperson;
......
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