diff --git a/app/api/src/games/games.controller.ts b/app/api/src/games/games.controller.ts index 36af8a5..5ffa0ee 100644 --- a/app/api/src/games/games.controller.ts +++ b/app/api/src/games/games.controller.ts @@ -10,13 +10,19 @@ export class GamesController { // /games @Get() findAll(@Query() paginationQuery: PaginationQueryDto) { - //const { limit, offset } = paginationQuery; - return this.gameService.findAll({ limit: 100, offset: 0 }); + const { limit = 10, offset = 0 } = paginationQuery; + return this.gameService.findAll({ limit, offset }); + } + + // /gametype/:gameId + @Get('gametype/:gametype') + findByType(@Param('gametype') gametype: string) { + return this.gameService.findByType(gametype); } // /game/:gameId @Get(':gameId') findOne(@Param('gameId') gameId: string) { - return ''; + return this.gameService.findOne(gameId); } } diff --git a/app/api/src/games/games.service.ts b/app/api/src/games/games.service.ts index 012b75f..4d62b3e 100644 --- a/app/api/src/games/games.service.ts +++ b/app/api/src/games/games.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { Connection, Repository } from 'typeorm'; @@ -18,9 +18,28 @@ export class GamesService { const { limit, offset } = paginationQuery; const games = await this.gamesRepository.find({ skip: offset, - take: limit + take: limit, + order: { + gameId: 'DESC' + } }); return games; } + + async findByType(gametype: string) { + const game = await this.gamesRepository.find({ where: { gametype: gametype } }); + if (!game) { + throw new NotFoundException(`Game Type: ${gametype} not found`); + } + return game; + } + + async findOne(gameId: string) { + const game = await this.gamesRepository.findOne(gameId); + if (!game) { + throw new NotFoundException(`Game ID: ${gameId} not found`); + } + return game; + } }