|
@ -51,7 +51,7 @@ export class PortfolioController { |
|
|
@Get('investments') |
|
|
@Get('investments') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async findAll( |
|
|
public async findAll( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<InvestmentItem[]> { |
|
|
): Promise<InvestmentItem[]> { |
|
|
if ( |
|
|
if ( |
|
@ -87,7 +87,7 @@ export class PortfolioController { |
|
|
@Get('chart') |
|
|
@Get('chart') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getChart( |
|
|
public async getChart( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range, |
|
|
@Query('range') range, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<PortfolioChart> { |
|
|
): Promise<PortfolioChart> { |
|
@ -98,18 +98,14 @@ export class PortfolioController { |
|
|
|
|
|
|
|
|
let chartData = historicalDataContainer.items; |
|
|
let chartData = historicalDataContainer.items; |
|
|
|
|
|
|
|
|
let hasNullValue = false; |
|
|
let hasError = false; |
|
|
|
|
|
|
|
|
chartData.forEach((chartDataItem) => { |
|
|
chartData.forEach((chartDataItem) => { |
|
|
if (hasNotDefinedValuesInObject(chartDataItem)) { |
|
|
if (hasNotDefinedValuesInObject(chartDataItem)) { |
|
|
hasNullValue = true; |
|
|
hasError = true; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
if (hasNullValue) { |
|
|
|
|
|
res.status(StatusCodes.ACCEPTED); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
|
this.userService.isRestrictedView(this.request.user) |
|
|
this.userService.isRestrictedView(this.request.user) |
|
@ -131,6 +127,7 @@ export class PortfolioController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return <any>res.json({ |
|
|
return <any>res.json({ |
|
|
|
|
|
hasError, |
|
|
chart: chartData, |
|
|
chart: chartData, |
|
|
isAllTimeHigh: historicalDataContainer.isAllTimeHigh, |
|
|
isAllTimeHigh: historicalDataContainer.isAllTimeHigh, |
|
|
isAllTimeLow: historicalDataContainer.isAllTimeLow |
|
|
isAllTimeLow: historicalDataContainer.isAllTimeLow |
|
@ -140,7 +137,7 @@ export class PortfolioController { |
|
|
@Get('details') |
|
|
@Get('details') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getDetails( |
|
|
public async getDetails( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range, |
|
|
@Query('range') range, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<PortfolioDetails> { |
|
|
): Promise<PortfolioDetails> { |
|
@ -152,6 +149,8 @@ export class PortfolioController { |
|
|
return <any>res.json({ accounts: {}, holdings: {} }); |
|
|
return <any>res.json({ accounts: {}, holdings: {} }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let hasError = false; |
|
|
|
|
|
|
|
|
const { accounts, holdings, hasErrors } = |
|
|
const { accounts, holdings, hasErrors } = |
|
|
await this.portfolioService.getDetails( |
|
|
await this.portfolioService.getDetails( |
|
|
impersonationId, |
|
|
impersonationId, |
|
@ -160,7 +159,7 @@ export class PortfolioController { |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (hasErrors || hasNotDefinedValuesInObject(holdings)) { |
|
|
if (hasErrors || hasNotDefinedValuesInObject(holdings)) { |
|
|
res.status(StatusCodes.ACCEPTED); |
|
|
hasError = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
@ -198,43 +197,38 @@ export class PortfolioController { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return <any>res.json({ accounts, holdings }); |
|
|
return <any>res.json({ accounts, hasError, holdings }); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Get('performance') |
|
|
@Get('performance') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getPerformance( |
|
|
public async getPerformance( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range, |
|
|
@Query('range') range, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<PortfolioPerformance> { |
|
|
): Promise<{ hasErrors: boolean; performance: PortfolioPerformance }> { |
|
|
const performanceInformation = await this.portfolioService.getPerformance( |
|
|
const performanceInformation = await this.portfolioService.getPerformance( |
|
|
impersonationId, |
|
|
impersonationId, |
|
|
range |
|
|
range |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (performanceInformation?.hasErrors) { |
|
|
|
|
|
res.status(StatusCodes.ACCEPTED); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let performance = performanceInformation.performance; |
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
|
this.userService.isRestrictedView(this.request.user) |
|
|
this.userService.isRestrictedView(this.request.user) |
|
|
) { |
|
|
) { |
|
|
performance = nullifyValuesInObject(performance, [ |
|
|
performanceInformation.performance = nullifyValuesInObject( |
|
|
'currentGrossPerformance', |
|
|
performanceInformation.performance, |
|
|
'currentValue' |
|
|
['currentGrossPerformance', 'currentValue'] |
|
|
]); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return <any>res.json(performance); |
|
|
return <any>res.json(performanceInformation); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Get('positions') |
|
|
@Get('positions') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getPositions( |
|
|
public async getPositions( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Query('range') range, |
|
|
@Query('range') range, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<PortfolioPositions> { |
|
|
): Promise<PortfolioPositions> { |
|
@ -243,10 +237,6 @@ export class PortfolioController { |
|
|
range |
|
|
range |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if (result?.hasErrors) { |
|
|
|
|
|
res.status(StatusCodes.ACCEPTED); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
if ( |
|
|
impersonationId || |
|
|
impersonationId || |
|
|
this.userService.isRestrictedView(this.request.user) |
|
|
this.userService.isRestrictedView(this.request.user) |
|
@ -353,7 +343,7 @@ export class PortfolioController { |
|
|
@Get('position/:symbol') |
|
|
@Get('position/:symbol') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getPosition( |
|
|
public async getPosition( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Param('symbol') symbol |
|
|
@Param('symbol') symbol |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
): Promise<PortfolioPositionDetail> { |
|
|
let position = await this.portfolioService.getPosition( |
|
|
let position = await this.portfolioService.getPosition( |
|
@ -387,7 +377,7 @@ export class PortfolioController { |
|
|
@Get('report') |
|
|
@Get('report') |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
@UseGuards(AuthGuard('jwt')) |
|
|
public async getReport( |
|
|
public async getReport( |
|
|
@Headers('impersonation-id') impersonationId, |
|
|
@Headers('impersonation-id') impersonationId: string, |
|
|
@Res() res: Response |
|
|
@Res() res: Response |
|
|
): Promise<PortfolioReport> { |
|
|
): Promise<PortfolioReport> { |
|
|
if ( |
|
|
if ( |
|
|