init new api endpoint for returning games by game type with summaries

This commit is contained in:
Anthony Mineo 2020-09-17 16:57:45 -04:00
parent 80056903c6
commit 69f250871a
3 changed files with 34 additions and 1 deletions

View file

@ -25,10 +25,19 @@ export class GamesController {
return this.gamesService.findAllWithSummary({ limit, offset }); return this.gamesService.findAllWithSummary({ limit, offset });
} }
// /gametype/:gametype // /games/gametype/:gametype
@Get('gametype/:gametype') @Get('gametype/:gametype')
@ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' }) @ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' })
findByType(@Param('gametype') gametype: string) { findByType(@Param('gametype') gametype: string) {
return this.gamesService.findByType(gametype); 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 });
}
} }

View file

@ -64,4 +64,27 @@ export class GamesService {
} }
return game; 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;
}
} }

View file

@ -42,6 +42,7 @@ services:
- .env - .env
ports: ports:
- "8080:8080" - "8080:8080"
- "8443:8443"
volumes: volumes:
- ./build/api/ecosystem._PROD_.config.js:/opt/node_app/ecosystem._PROD_.config.js - ./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 - ./build/api/ecosystem._DEV_.config.js:/opt/node_app/ecosystem._DEV_.config.js