diff --git a/app/api/src/game/game.module.ts b/app/api/src/game/game.module.ts index 06cd534..8e590bc 100644 --- a/app/api/src/game/game.module.ts +++ b/app/api/src/game/game.module.ts @@ -13,6 +13,7 @@ import { Players } from '../players/entities/Players'; @Module({ imports: [ TypeOrmModule.forFeature([ Games, GameDetail, Players ]), ConfigModule ], controllers: [ GameController ], - providers: [ GameService ] + providers: [ GameService ], + exports: [ GameService ] }) export class GameModule {} diff --git a/app/api/src/games/games.controller.ts b/app/api/src/games/games.controller.ts index f85014d..d9af313 100644 --- a/app/api/src/games/games.controller.ts +++ b/app/api/src/games/games.controller.ts @@ -6,20 +6,29 @@ import { PaginationQueryDto } from '../common/dto/pagination-query.dto'; @Controller('games') export class GamesController { - constructor(private readonly gameService: GamesService) {} + constructor(private readonly gamesService: GamesService) {} // /games @Get() @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games' }) findAll(@Query() paginationQuery: PaginationQueryDto) { const { limit = 10, offset = 0 } = paginationQuery; - return this.gameService.findAll({ limit, offset }); + return this.gamesService.findAll({ limit, offset }); + } + + // /games/summary + @Get('summary') + @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games with summary' }) + findAllWithSummary(@Query() paginationQuery: PaginationQueryDto) { + const { limit = 10, offset = 0 } = paginationQuery; + + return this.gamesService.findAllWithSummary({ limit, offset }); } // /gametype/:gametype @Get('gametype/:gametype') @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' }) findByType(@Param('gametype') gametype: string) { - return this.gameService.findByType(gametype); + return this.gamesService.findByType(gametype); } } diff --git a/app/api/src/games/games.module.ts b/app/api/src/games/games.module.ts index bca13a2..826604d 100644 --- a/app/api/src/games/games.module.ts +++ b/app/api/src/games/games.module.ts @@ -7,9 +7,10 @@ import { GamesService } from './games.service'; import { Games } from './entities/Games'; import { GameDetail } from '../game/entities/GameDetail'; +import { GameModule } from '../game/game.module'; @Module({ - imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule ], + imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule, GameModule ], controllers: [ GamesController ], providers: [ GamesService ] }) diff --git a/app/api/src/games/games.service.ts b/app/api/src/games/games.service.ts index 5b11809..f58cf0a 100644 --- a/app/api/src/games/games.service.ts +++ b/app/api/src/games/games.service.ts @@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm'; import { Connection, Repository } from 'typeorm'; import { Games } from './entities/Games'; +import { GameService } from '../game/game.service'; import { PaginationQueryDto } from '../common/dto/pagination-query.dto'; @Injectable() @@ -11,6 +12,7 @@ export class GamesService { constructor( private readonly connection: Connection, private readonly configService: ConfigService, + private readonly gameService: GameService, @InjectRepository(Games) private readonly gamesRepository: Repository ) {} @@ -27,6 +29,27 @@ export class GamesService { return games; } + async findAllWithSummary(paginationQuery: PaginationQueryDto) { + const { limit, offset } = paginationQuery; + const games = await this.gamesRepository.find({ + skip: offset, + take: limit, + order: { + gameId: 'DESC' + } + }); + + const withSummary = []; + for (const game of games) { + const summary = await this.gameService.findOne(game.gameId); + withSummary.push(summary); + } + + // Game findOne service needs to bubble up the game details as parent object and set players below it + + return withSummary; + } + async findByType(gametype: string) { const game = await this.gamesRepository.find({ where: { gametype: gametype },