From 69f250871a05342f9360ddc4411318ac16b9d39f Mon Sep 17 00:00:00 2001 From: Anthony Mineo Date: Thu, 17 Sep 2020 16:57:45 -0400 Subject: [PATCH] init new api endpoint for returning games by game type with summaries --- app/api/src/games/games.controller.ts | 11 ++++++++++- app/api/src/games/games.service.ts | 23 +++++++++++++++++++++++ docker-compose.override.yml | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/api/src/games/games.controller.ts b/app/api/src/games/games.controller.ts index d9af313..f90f164 100644 --- a/app/api/src/games/games.controller.ts +++ b/app/api/src/games/games.controller.ts @@ -25,10 +25,19 @@ export class GamesController { return this.gamesService.findAllWithSummary({ limit, offset }); } - // /gametype/:gametype + // /games/gametype/:gametype @Get('gametype/:gametype') @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' }) findByType(@Param('gametype') gametype: string) { return this.gamesService.findByType(gametype); } + + // /games/gametype/CTFGame/summary + @Get('gametype/:gametype/summary') + @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type with game summaries' }) + findByTypeWithSummary(@Param('gametype') gametype: string, @Query() paginationQuery: PaginationQueryDto) { + const { limit = 10, offset = 0 } = paginationQuery; + + return this.gamesService.findByTypeWithSummary(gametype, { limit, offset }); + } } diff --git a/app/api/src/games/games.service.ts b/app/api/src/games/games.service.ts index f58cf0a..94fdf46 100644 --- a/app/api/src/games/games.service.ts +++ b/app/api/src/games/games.service.ts @@ -64,4 +64,27 @@ export class GamesService { } return game; } + + async findByTypeWithSummary(gametype: string, paginationQuery: PaginationQueryDto) { + const { limit, offset } = paginationQuery; + const games = await this.gamesRepository.find({ + where: { gametype: gametype }, + skip: offset, + take: limit, + order: { + gameId: 'DESC' + } + }); + if (!games.length) { + throw new NotFoundException(`Game Type: ${gametype} not found`); + } + + const withSummary = []; + for (const game of games) { + const summary = await this.gameService.findOne(game.gameId); + withSummary.push(summary); + } + + return withSummary; + } } diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 629a48d..7ec1524 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -42,6 +42,7 @@ services: - .env ports: - "8080:8080" + - "8443:8443" volumes: - ./build/api/ecosystem._PROD_.config.js:/opt/node_app/ecosystem._PROD_.config.js - ./build/api/ecosystem._DEV_.config.js:/opt/node_app/ecosystem._DEV_.config.js