diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 8d7494ba4dfa4a77e22963600e45a7579fca5d5d..a0b85a24e645f99bff5d1b4175bc6e9b24d1353f 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -55,8 +55,13 @@ export class GameController { } @Get('listgames') - async listGames() { - return this.gameservice.listGames(); + async listGames(state) { + return this.gameservice.listGames(state); + } + + @Get('listgames/:state') + async listGamesState(@Param('state') state: string) { + return this.gameservice.listGames(state); } // ClassSerializerInterceptor removes excluded columns set in Entities diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts index 266a8b1564e5b11fb42da755359c79d37f4b170b..abf1742d2af2bd9e10eed82b264217af11f96d8c 100644 --- a/src/game/game.dto.ts +++ b/src/game/game.dto.ts @@ -76,7 +76,7 @@ export class newGameDTO { export class GameStateDTO { @IsUUID('4') id: string; - @IsIn(['CREATED', 'STARTED', 'PAUSED', 'ENDED']) + @IsIn(['CREATED', 'STARTED', 'PAUSED', 'ENDED', 'ONGOING']) state: string; } diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 3f6506b649f7dbe09936e283b4658f9765be8ec4..391d812fb2cad207ded708cf5bf619e0065b5009 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -170,11 +170,31 @@ export class GameService { } // returns name and id of each game - async listGames() { - const games = await this.gameRepository.find(); - return games.map(game => { - return game.gameObject(); - }); + async listGames(state) { + if(state == null){ + const games = await this.gameRepository.find(); + return games.map(game => { + return game.gameObject(); + }); + } + else if(state == 'ONGOING'){ + const games = await this.gameRepository.find({ + where: [ + {state: 'CREATED'}, {state: 'STARTED'}, {state: 'PAUSED'}, + ] + }); + return games.map(game => { + return game.gameObject(); + }); + } + else{ + const games = await this.gameRepository.find({ + where: {state: state} + }); + return games.map(game => { + return game.gameObject(); + }); + } } // returns information about a game identified by id