Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

add error handling to performance aggregation

Valentin Zicknerb779964adb0b
diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts
index 2cd1259d98..6c701cbe55 100644
--- a/apps/api/src/app/portfolio/portfolio.service.ts
+++ b/apps/api/src/app/portfolio/portfolio.service.ts
@@ -468,16 +468,23 @@ export class PortfolioService {
let currentValue = new Big(0);
let grossPerformance = new Big(0);
let grossPerformancePercentage = new Big(1);
+ let hasErrors = false;
for (const currentPosition of currentPositions.positions) {
currentValue = currentValue.add(
new Big(currentPosition.marketPrice).mul(currentPosition.quantity)
);
- grossPerformance = grossPerformance.plus(
- currentPosition.grossPerformance
- );
- grossPerformancePercentage = grossPerformancePercentage.mul(
- currentPosition.grossPerformancePercentage.plus(1)
- );
+ if (currentPosition.grossPerformance) {
+ hasErrors = true;
+ grossPerformance = grossPerformance.plus(
+ currentPosition.grossPerformance
+ );
+ }
+ if (currentPosition.grossPerformancePercentage) {
+ hasErrors = true;
+ grossPerformancePercentage = grossPerformancePercentage.mul(
+ currentPosition.grossPerformancePercentage.plus(1)
+ );
+ }
}
const currentGrossPerformance = grossPerformance.toNumber();
@@ -485,7 +492,7 @@ export class PortfolioService {
.minus(1)
.toNumber();
return {
- hasErrors: currentPositions.hasErrors,
+ hasErrors: currentPositions.hasErrors || hasErrors,
performance: {
currentGrossPerformance,
currentGrossPerformancePercent,