mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
init new api endpoint for returning games by game type with summaries
This commit is contained in:
parent
80056903c6
commit
69f250871a
|
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue