Skip to content
Snippets Groups Projects
Commit 06ae9f3b authored by L4072's avatar L4072
Browse files

Can list games according to one or more statuses

parent 8e92a18e
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 {
}
@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
......
......@@ -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;
}
......
......@@ -174,11 +174,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
......
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