Skip to content
Snippets Groups Projects

Development to testing

Merged Ghost User requested to merge Development into testing
7 files
+ 61
51
Compare changes
  • Side-by-side
  • Inline
Files
7
@@ -10,12 +10,17 @@ import {
UseInterceptors,
ClassSerializerInterceptor,
Delete,
UploadedFile,
Res,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname } from 'path';
import { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard';
import { User } from '../user/user.decorator';
import { GameDTO, FlagboxEventDTO, GameStateDTO } from './game.dto';
import { GameDTO, FlagboxEventDTO, GameStateDTO, newGameDTO } from './game.dto';
import { ValidationPipe } from '../shared/validation.pipe';
import { Roles, GameStates } from '../shared/guard.decorator';
import { GameEntity } from './game.entity';
@@ -33,13 +38,15 @@ import { GameEntity } from './game.entity';
export class GameController {
constructor(private gameservice: GameService) {}
//new game
@Post('new')
@UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe())
async newGame(@User('id') person, @Body() body: GameDTO) {
async newGame(@User('id') person, @Body() body: newGameDTO) {
return this.gameservice.createNewGame(person, body);
}
// edit game
@Put('edit/:id')
@Roles('admin')
@GameStates('CREATED')
@@ -49,6 +56,7 @@ export class GameController {
return this.gameservice.editGame(id, body);
}
// delete game
@Delete('delete/:id')
@Roles('admin')
@GameStates('CREATED')
@@ -56,6 +64,7 @@ export class GameController {
return this.gameservice.deleteGame(id);
}
// change game state
@Put('edit-state/:id')
@Roles('admin')
@UsePipes(new ValidationPipe())
@@ -63,11 +72,13 @@ export class GameController {
return this.gameservice.updateGameStatus(body);
}
// list all games
@Get('listgames')
async listGames(state) {
return this.gameservice.listGames(state);
}
// list games based on parameter
@Get('listgames/:state')
async listGamesState(@Param('state') state: string) {
return this.gameservice.listGames(state);
@@ -80,20 +91,57 @@ export class GameController {
return this.gameservice.returnGameInfo(id);
}
//get all factions
@Get('get-factions/:id')
@Roles('admin')
async returnGameFactions(@Param('id') id: GameEntity) {
return this.gameservice.listFactions(id);
}
// get flagbox events
@Get('flag-events/:id')
async returnFlagboxInfo(@Param('id') id: GameEntity) {
return this.gameservice.returnObjectivePointInfo(id);
}
// initial settings for flagbox
@Get('flag/:id')
async flagboxQuery(@Param('id') id: string) {
return this.gameservice.flagboxQuery(id);
}
// flagbox event
@Post('flag/:id')
@GameStates('STARTED')
async flagboxEvent(@Param('id') id: string, @Body() data: FlagboxEventDTO) {
return this.gameservice.flagboxEvent(id, data);
}
// image upload
@Post('upload')
@UseInterceptors(
FileInterceptor('image', {
storage: diskStorage({
destination: './images',
filename: (req, file, cb) => {
// Generating a 32 random chars long string
const randomName = Array(32)
.fill(null)
.map(() => Math.round(Math.random() * 16).toString(16))
.join('');
//Calling the callback passing the random name generated with the original extension name
cb(null, `${randomName}${extname(file.originalname)}`);
},
}),
}),
)
uploadImage(@UploadedFile() image) {
return image;
}
// get images
@Get('images/:img')
returnImage(@Param('img') image, @Res() res) {
return res.sendFile(image, { root: 'images' });
}
}
Loading