fix: little fixes
This commit is contained in:
@@ -21,6 +21,7 @@ import { CredentialsDto } from './auth.dto';
|
|||||||
import { AuthService } from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import { AccessPayload } from './auth.types';
|
import { AccessPayload } from './auth.types';
|
||||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||||
|
import { ApiProblemResponses } from '../common/decorators/api-safe-error-response.decorator';
|
||||||
|
|
||||||
const REFRESH_COOKIE = 'refresh_token';
|
const REFRESH_COOKIE = 'refresh_token';
|
||||||
const COOKIE_PATH = '/api/v1/auth';
|
const COOKIE_PATH = '/api/v1/auth';
|
||||||
@@ -42,6 +43,7 @@ class AuthenticationDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiTags('auth')
|
@ApiTags('auth')
|
||||||
|
@ApiProblemResponses()
|
||||||
@Controller('auth')
|
@Controller('auth')
|
||||||
export class AuthController {
|
export class AuthController {
|
||||||
constructor(private readonly auth: AuthService) {}
|
constructor(private readonly auth: AuthService) {}
|
||||||
|
|||||||
@@ -1,19 +1,43 @@
|
|||||||
import { ApiInternalServerErrorResponse, ApiProperty } from '@nestjs/swagger';
|
import { applyDecorators } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
ApiExtraModels,
|
||||||
|
ApiProperty,
|
||||||
|
ApiResponse,
|
||||||
|
getSchemaPath,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
|
||||||
export class SafeErrorResponseDto {
|
export class ProblemDetailsDto {
|
||||||
@ApiProperty({ example: 500 })
|
@ApiProperty({ example: 401 })
|
||||||
statusCode: number;
|
status: number;
|
||||||
|
|
||||||
@ApiProperty({ example: 'Internal server error' })
|
@ApiProperty({ example: 'UNAUTHORIZED' })
|
||||||
message: string;
|
code: string;
|
||||||
|
|
||||||
@ApiProperty({ example: '/api/v1' })
|
@ApiProperty({
|
||||||
path: string;
|
required: false,
|
||||||
|
example: [{ pointer: '#/email', detail: 'must be a valid email address' }],
|
||||||
|
})
|
||||||
|
errors?: { pointer: string; detail: string }[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ApiSafeErrorResponse(): MethodDecorator & ClassDecorator {
|
function problemResponse(status: number, description: string) {
|
||||||
return ApiInternalServerErrorResponse({
|
return ApiResponse({
|
||||||
description: 'Internal server error',
|
status,
|
||||||
type: SafeErrorResponseDto,
|
description,
|
||||||
|
content: {
|
||||||
|
'application/problem+json': {
|
||||||
|
schema: { $ref: getSchemaPath(ProblemDetailsDto) },
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ApiProblemResponses(): MethodDecorator & ClassDecorator {
|
||||||
|
return applyDecorators(
|
||||||
|
ApiExtraModels(ProblemDetailsDto),
|
||||||
|
problemResponse(400, 'Invalid request'),
|
||||||
|
problemResponse(401, 'Authentication required'),
|
||||||
|
problemResponse(404, 'Resource not found'),
|
||||||
|
problemResponse(500, 'Internal server error'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
|||||||
import type { Request } from 'express';
|
import type { Request } from 'express';
|
||||||
import { AccessPayload } from '../auth/auth.types';
|
import { AccessPayload } from '../auth/auth.types';
|
||||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||||
|
import { ApiProblemResponses } from '../common/decorators/api-safe-error-response.decorator';
|
||||||
import { BrokerageAccountDto } from './brokerage-account.dto';
|
import { BrokerageAccountDto } from './brokerage-account.dto';
|
||||||
import { BrokerageAccountsService } from './brokerage-accounts.service';
|
import { BrokerageAccountsService } from './brokerage-accounts.service';
|
||||||
|
|
||||||
@ApiTags('brokerage-accounts')
|
@ApiTags('brokerage-accounts')
|
||||||
|
@ApiProblemResponses()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('brokerage-accounts')
|
@Controller('brokerage-accounts')
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
|||||||
import type { Request } from 'express';
|
import type { Request } from 'express';
|
||||||
import { AccessPayload } from '../auth/auth.types';
|
import { AccessPayload } from '../auth/auth.types';
|
||||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||||
|
import { ApiProblemResponses } from '../common/decorators/api-safe-error-response.decorator';
|
||||||
import { PortfolioDto } from './portfolio.dto';
|
import { PortfolioDto } from './portfolio.dto';
|
||||||
import { PortfolioService } from './portfolio.service';
|
import { PortfolioService } from './portfolio.service';
|
||||||
|
|
||||||
@ApiTags('brokerage-accounts')
|
@ApiTags('brokerage-accounts')
|
||||||
|
@ApiProblemResponses()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('brokerage-accounts')
|
@Controller('brokerage-accounts')
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
import type { Request } from 'express';
|
import type { Request } from 'express';
|
||||||
import { AccessPayload } from '../auth/auth.types';
|
import { AccessPayload } from '../auth/auth.types';
|
||||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||||
|
import { ApiProblemResponses } from '../common/decorators/api-safe-error-response.decorator';
|
||||||
import {
|
import {
|
||||||
PutTbankConnectionDto,
|
PutTbankConnectionDto,
|
||||||
TbankConnectionStatusDto,
|
TbankConnectionStatusDto,
|
||||||
@@ -24,6 +25,7 @@ import {
|
|||||||
import { TbankConnectionService } from './tbank-connection.service';
|
import { TbankConnectionService } from './tbank-connection.service';
|
||||||
|
|
||||||
@ApiTags('tbank-connection')
|
@ApiTags('tbank-connection')
|
||||||
|
@ApiProblemResponses()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('tbank-connection')
|
@Controller('tbank-connection')
|
||||||
|
|||||||
Reference in New Issue
Block a user