|
@ -38,7 +38,7 @@ import { StatusCodes, getReasonPhrase } from 'http-status-codes'; |
|
|
|
|
|
|
|
|
import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; |
|
|
import { PortfolioPositionDetail } from './interfaces/portfolio-position-detail.interface'; |
|
|
import { PortfolioPositions } from './interfaces/portfolio-positions.interface'; |
|
|
import { PortfolioPositions } from './interfaces/portfolio-positions.interface'; |
|
|
import { PortfolioServiceStrategy } from './portfolio-service.strategy'; |
|
|
import { PortfolioServiceNew } from './portfolio.service-new'; |
|
|
|
|
|
|
|
|
@Controller('portfolio') |
|
|
@Controller('portfolio') |
|
|
export class PortfolioController { |
|
|
export class PortfolioController { |
|
@ -46,7 +46,7 @@ export class PortfolioController { |
|
|
private readonly accessService: AccessService, |
|
|
private readonly accessService: AccessService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly configurationService: ConfigurationService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly exchangeRateDataService: ExchangeRateDataService, |
|
|
private readonly portfolioServiceStrategy: PortfolioServiceStrategy, |
|
|
private readonly portfolioServiceNew: PortfolioServiceNew, |
|
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
|
|
@Inject(REQUEST) private readonly request: RequestWithUser, |
|
|
private readonly userService: UserService |
|
|
private readonly userService: UserService |
|
|
) {} |
|
|
) {} |
|
@ -57,9 +57,10 @@ export class PortfolioController { |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range |
|
|
@Query('range') range |
|
|
): Promise<PortfolioChart> { |
|
|
): Promise<PortfolioChart> { |
|
|
const historicalDataContainer = await this.portfolioServiceStrategy |
|
|
const historicalDataContainer = await this.portfolioServiceNew.getChart( |
|
|
.get() |
|
|
impersonationId, |
|
|
.getChart(impersonationId, range); |
|
|
range |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
let chartData = historicalDataContainer.items; |
|
|
let chartData = historicalDataContainer.items; |
|
|
|
|
|
|
|
@ -109,9 +110,11 @@ export class PortfolioController { |
|
|
let hasError = false; |
|
|
let hasError = false; |
|
|
|
|
|
|
|
|
const { accounts, holdings, hasErrors } = |
|
|
const { accounts, holdings, hasErrors } = |
|
|
await this.portfolioServiceStrategy |
|
|
await this.portfolioServiceNew.getDetails( |
|
|
.get(true) |
|
|
impersonationId, |
|
|
.getDetails(impersonationId, this.request.user.id, range); |
|
|
this.request.user.id, |
|
|
|
|
|
range |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (hasErrors || hasNotDefinedValuesInObject(holdings)) { |
|
|
if (hasErrors || hasNotDefinedValuesInObject(holdings)) { |
|
|
hasError = true; |
|
|
hasError = true; |
|
@ -174,9 +177,9 @@ export class PortfolioController { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let investments = await this.portfolioServiceStrategy |
|
|
let investments = await this.portfolioServiceNew.getInvestments( |
|
|
.get() |
|
|
impersonationId |
|
|
.getInvestments(impersonationId); |
|
|
); |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
@ -203,9 +206,8 @@ export class PortfolioController { |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range |
|
|
@Query('range') range |
|
|
): Promise<PortfolioPerformanceResponse> { |
|
|
): Promise<PortfolioPerformanceResponse> { |
|
|
const performanceInformation = await this.portfolioServiceStrategy |
|
|
const performanceInformation = |
|
|
.get() |
|
|
await this.portfolioServiceNew.getPerformance(impersonationId, range); |
|
|
.getPerformance(impersonationId, range); |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
@ -228,9 +230,10 @@ export class PortfolioController { |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range |
|
|
@Query('range') range |
|
|
): Promise<PortfolioPositions> { |
|
|
): Promise<PortfolioPositions> { |
|
|
const result = await this.portfolioServiceStrategy |
|
|
const result = await this.portfolioServiceNew.getPositions( |
|
|
.get() |
|
|
impersonationId, |
|
|
.getPositions(impersonationId, range); |
|
|
range |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
@ -270,9 +273,10 @@ export class PortfolioController { |
|
|
hasDetails = user.subscription.type === 'Premium'; |
|
|
hasDetails = user.subscription.type === 'Premium'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const { holdings } = await this.portfolioServiceStrategy |
|
|
const { holdings } = await this.portfolioServiceNew.getDetails( |
|
|
.get(true) |
|
|
access.userId, |
|
|
.getDetails(access.userId, access.userId); |
|
|
access.userId |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
const portfolioPublicDetails: PortfolioPublicDetails = { |
|
|
const portfolioPublicDetails: PortfolioPublicDetails = { |
|
|
hasDetails, |
|
|
hasDetails, |
|
@ -324,9 +328,7 @@ export class PortfolioController { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let summary = await this.portfolioServiceStrategy |
|
|
let summary = await this.portfolioServiceNew.getSummary(impersonationId); |
|
|
.get() |
|
|
|
|
|
.getSummary(impersonationId); |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
@ -360,9 +362,11 @@ export class PortfolioController { |
|
|
@Param('dataSource') dataSource, |
|
|
@Param('dataSource') dataSource, |
|
|
@Param('symbol') symbol |
|
|
@Param('symbol') symbol |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
let position = await this.portfolioServiceStrategy |
|
|
let position = await this.portfolioServiceNew.getPosition( |
|
|
.get() |
|
|
dataSource, |
|
|
.getPosition(dataSource, impersonationId, symbol); |
|
|
impersonationId, |
|
|
|
|
|
symbol |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
if (position) { |
|
|
if (position) { |
|
|
if ( |
|
|
if ( |
|
@ -403,6 +407,6 @@ export class PortfolioController { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return await this.portfolioServiceStrategy.get().getReport(impersonationId); |
|
|
return await this.portfolioServiceNew.getReport(impersonationId); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|