|
@@ -1,18 +1,21 @@
|
|
|
import {
|
|
|
+ Body,
|
|
|
Controller,
|
|
|
Get,
|
|
|
HttpException,
|
|
|
HttpStatus,
|
|
|
Patch,
|
|
|
+ Post,
|
|
|
Query,
|
|
|
Redirect,
|
|
|
Req,
|
|
|
UseGuards,
|
|
|
} from '@nestjs/common';
|
|
|
-import { ApiQuery } from '@nestjs/swagger';
|
|
|
+import { ApiBody, ApiQuery, ApiResponse } from '@nestjs/swagger';
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
import { AuthService } from './auth.service';
|
|
|
import { JwtGuard } from './guards/jwt.guard';
|
|
|
+import { RadarScopeDto } from './dto/radarscope.dto';
|
|
|
import { UserDto } from './dto/user.dto';
|
|
|
import { Request } from 'express';
|
|
|
|
|
@@ -57,6 +60,36 @@ export class AuthController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Post('/radarScope')
|
|
|
+ @ApiBody({
|
|
|
+ description: 'The airport definition',
|
|
|
+ type: RadarScopeDto,
|
|
|
+ })
|
|
|
+ @ApiResponse({
|
|
|
+ status: 200,
|
|
|
+ description: 'The created Bearer token to use endpoints',
|
|
|
+ type: String,
|
|
|
+ })
|
|
|
+ @ApiResponse({
|
|
|
+ status: 404,
|
|
|
+ description: 'The VATSIM ID and key combination is invalid',
|
|
|
+ })
|
|
|
+ async radarScope(
|
|
|
+ @Body('scopeData') scopeData: RadarScopeDto,
|
|
|
+ ): Promise<string> {
|
|
|
+ return this.authService
|
|
|
+ .loginRadarScope(scopeData.vatsimId, scopeData.key)
|
|
|
+ .then((token) => {
|
|
|
+ if (token === undefined) {
|
|
|
+ throw new HttpException(
|
|
|
+ 'Unknown VATSIM ID or invalid key',
|
|
|
+ HttpStatus.NOT_FOUND,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return token;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@UseGuards(JwtGuard)
|
|
|
@Get('/user')
|
|
|
async user(@Req() request: Request): Promise<UserDto> {
|