|
|
@ -20,6 +20,7 @@ import { |
|
|
|
import { |
|
|
|
PortfolioDetails, |
|
|
|
PortfolioDividends, |
|
|
|
PortfolioHoldingResponse, |
|
|
|
PortfolioHoldingsResponse, |
|
|
|
PortfolioInvestments, |
|
|
|
PortfolioPerformanceResponse, |
|
|
@ -56,7 +57,6 @@ import { AssetClass, AssetSubClass, DataSource } from '@prisma/client'; |
|
|
|
import { Big } from 'big.js'; |
|
|
|
import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|
|
|
|
|
|
|
import { PortfolioHoldingDetail } from './interfaces/portfolio-holding-detail.interface'; |
|
|
|
import { PortfolioService } from './portfolio.service'; |
|
|
|
import { UpdateHoldingTagsDto } from './update-holding-tags.dto'; |
|
|
|
|
|
|
@ -365,6 +365,32 @@ export class PortfolioController { |
|
|
|
return { dividends }; |
|
|
|
} |
|
|
|
|
|
|
|
@Get('holding/:dataSource/:symbol') |
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor) |
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor) |
|
|
|
@UseInterceptors(TransformDataSourceInResponseInterceptor) |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
public async getHolding( |
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId: string, |
|
|
|
@Param('dataSource') dataSource: DataSource, |
|
|
|
@Param('symbol') symbol: string |
|
|
|
): Promise<PortfolioHoldingResponse> { |
|
|
|
const holding = await this.portfolioService.getHolding( |
|
|
|
dataSource, |
|
|
|
impersonationId, |
|
|
|
symbol |
|
|
|
); |
|
|
|
|
|
|
|
if (!holding) { |
|
|
|
throw new HttpException( |
|
|
|
getReasonPhrase(StatusCodes.NOT_FOUND), |
|
|
|
StatusCodes.NOT_FOUND |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return holding; |
|
|
|
} |
|
|
|
|
|
|
|
@Get('holdings') |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor) |
|
|
@ -583,6 +609,9 @@ export class PortfolioController { |
|
|
|
return performanceInformation; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @deprecated |
|
|
|
*/ |
|
|
|
@Get('position/:dataSource/:symbol') |
|
|
|
@UseInterceptors(RedactValuesInResponseInterceptor) |
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor) |
|
|
@ -592,8 +621,8 @@ export class PortfolioController { |
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId: string, |
|
|
|
@Param('dataSource') dataSource: DataSource, |
|
|
|
@Param('symbol') symbol: string |
|
|
|
): Promise<PortfolioHoldingDetail> { |
|
|
|
const holding = await this.portfolioService.getPosition( |
|
|
|
): Promise<PortfolioHoldingResponse> { |
|
|
|
const holding = await this.portfolioService.getHolding( |
|
|
|
dataSource, |
|
|
|
impersonationId, |
|
|
|
symbol |
|
|
@ -634,7 +663,7 @@ export class PortfolioController { |
|
|
|
} |
|
|
|
|
|
|
|
@HasPermission(permissions.updateOrder) |
|
|
|
@Put('position/:dataSource/:symbol/tags') |
|
|
|
@Put('holding/:dataSource/:symbol/tags') |
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor) |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
public async updateHoldingTags( |
|
|
@ -643,7 +672,42 @@ export class PortfolioController { |
|
|
|
@Param('dataSource') dataSource: DataSource, |
|
|
|
@Param('symbol') symbol: string |
|
|
|
): Promise<void> { |
|
|
|
const holding = await this.portfolioService.getPosition( |
|
|
|
const holding = await this.portfolioService.getHolding( |
|
|
|
dataSource, |
|
|
|
impersonationId, |
|
|
|
symbol |
|
|
|
); |
|
|
|
|
|
|
|
if (!holding) { |
|
|
|
throw new HttpException( |
|
|
|
getReasonPhrase(StatusCodes.NOT_FOUND), |
|
|
|
StatusCodes.NOT_FOUND |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
await this.portfolioService.updateTags({ |
|
|
|
dataSource, |
|
|
|
impersonationId, |
|
|
|
symbol, |
|
|
|
tags: data.tags, |
|
|
|
userId: this.request.user.id |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @deprecated |
|
|
|
*/ |
|
|
|
@HasPermission(permissions.updateOrder) |
|
|
|
@Put('position/:dataSource/:symbol/tags') |
|
|
|
@UseInterceptors(TransformDataSourceInRequestInterceptor) |
|
|
|
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) |
|
|
|
public async updatePositionTags( |
|
|
|
@Body() data: UpdateHoldingTagsDto, |
|
|
|
@Headers(HEADER_KEY_IMPERSONATION.toLowerCase()) impersonationId: string, |
|
|
|
@Param('dataSource') dataSource: DataSource, |
|
|
|
@Param('symbol') symbol: string |
|
|
|
): Promise<void> { |
|
|
|
const holding = await this.portfolioService.getHolding( |
|
|
|
dataSource, |
|
|
|
impersonationId, |
|
|
|
symbol |
|
|
|