Enable swagger

This commit is contained in:
Anthony Mineo 2020-08-29 19:10:50 -04:00
parent 75f6e64a1f
commit a1b2f2cd78
4 changed files with 25 additions and 5 deletions

View file

@ -1,8 +1,12 @@
{
"name": "api",
"name": "playt2-stats-api",
"version": "0.0.1",
"description": "",
"author": "",
"description": "Open-API powering stats.playt2.com",
"authors": {
"name": "Anthony Mineo",
"email": "anthonymineo@gmail.com",
"url": "https://anthonymineo.com"
},
"private": true,
"license": "UNLICENSED",
"scripts": {
@ -75,4 +79,4 @@
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
}

View file

@ -1,4 +1,6 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { GameService } from './game.service';
@Controller('game')
@ -7,6 +9,7 @@ export class GameController {
// /games/:gameId
@Get(':gameId')
@ApiOperation({ summary: 'Find game by Id' })
findOne(@Param('gameId') gameId: string) {
return this.gameService.findOne(gameId);
}

View file

@ -20,7 +20,8 @@ export class GameService {
relations: [ 'game', 'playerGuid' ],
where: [ { game: { gameId: gameId } } ]
});
if (!query) {
if (!query.length) {
throw new NotFoundException(`Game ID: ${gameId} not found`);
}

View file

@ -1,5 +1,7 @@
import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';
async function bootstrap() {
@ -16,6 +18,16 @@ async function bootstrap() {
})
);
const swaggerOptions = new DocumentBuilder()
.setTitle('Tribes 2 Stats API')
.setDescription('Powering stats.playt2.com')
.setVersion('1.0')
.addTag('task')
.build();
const document = SwaggerModule.createDocument(app, swaggerOptions);
SwaggerModule.setup('api', app, document);
await app.listen(3000);
}
bootstrap();