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

Merge branch 'Score' into HEAD

parents 983c618c 06ae9f3b
No related branches found
No related tags found
3 merge requests!59Development to master,!44Development to testing,!37Can list games according to one or more statuses
...@@ -55,8 +55,13 @@ export class GameController { ...@@ -55,8 +55,13 @@ export class GameController {
} }
@Get('listgames') @Get('listgames')
async listGames() { async listGames(state) {
return this.gameservice.listGames(); 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 // ClassSerializerInterceptor removes excluded columns set in Entities
......
...@@ -76,7 +76,7 @@ export class newGameDTO { ...@@ -76,7 +76,7 @@ export class newGameDTO {
export class GameStateDTO { export class GameStateDTO {
@IsUUID('4') @IsUUID('4')
id: string; id: string;
@IsIn(['CREATED', 'STARTED', 'PAUSED', 'ENDED']) @IsIn(['CREATED', 'STARTED', 'PAUSED', 'ENDED', 'ONGOING'])
state: string; state: string;
} }
......
...@@ -170,11 +170,31 @@ export class GameService { ...@@ -170,11 +170,31 @@ export class GameService {
} }
// returns name and id of each game // returns name and id of each game
async listGames() { async listGames(state) {
const games = await this.gameRepository.find(); if(state == null){
return games.map(game => { const games = await this.gameRepository.find();
return game.gameObject(); 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 // returns information about a game identified by id
......
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