Browse Source

Refactoring

pull/3089/head
Thomas Kaul 2 years ago
parent
commit
c3dcb0cfa2
  1. 11
      apps/api/src/app/portfolio/portfolio-calculator.ts
  2. 18
      apps/client/src/app/services/import-activities.service.ts

11
apps/api/src/app/portfolio/portfolio-calculator.ts

@ -13,7 +13,6 @@ import {
import { GroupBy } from '@ghostfolio/common/types'; import { GroupBy } from '@ghostfolio/common/types';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import { Type as ActivityType } from '@prisma/client';
import Big from 'big.js'; import Big from 'big.js';
import { import {
addDays, addDays,
@ -971,7 +970,7 @@ export class PortfolioCalculator {
itemType: 'start', itemType: 'start',
name: '', name: '',
quantity: new Big(0), quantity: new Big(0),
type: ActivityType.BUY, type: 'BUY',
unitPrice: unitPriceAtStartDate unitPrice: unitPriceAtStartDate
}); });
@ -985,7 +984,7 @@ export class PortfolioCalculator {
itemType: 'end', itemType: 'end',
name: '', name: '',
quantity: new Big(0), quantity: new Big(0),
type: ActivityType.BUY, type: 'BUY',
unitPrice: unitPriceAtEndDate unitPrice: unitPriceAtEndDate
}); });
@ -1012,7 +1011,7 @@ export class PortfolioCalculator {
feeInBaseCurrency: new Big(0), feeInBaseCurrency: new Big(0),
name: '', name: '',
quantity: new Big(0), quantity: new Big(0),
type: ActivityType.BUY, type: 'BUY',
unitPrice: unitPrice:
marketSymbolMap[format(day, DATE_FORMAT)]?.[symbol] ?? marketSymbolMap[format(day, DATE_FORMAT)]?.[symbol] ??
lastUnitPrice lastUnitPrice
@ -1194,14 +1193,14 @@ export class PortfolioCalculator {
); );
const grossPerformanceFromSell = const grossPerformanceFromSell =
order.type === ActivityType.SELL order.type === 'SELL'
? order.unitPriceInBaseCurrency ? order.unitPriceInBaseCurrency
.minus(lastAveragePrice) .minus(lastAveragePrice)
.mul(order.quantity) .mul(order.quantity)
: new Big(0); : new Big(0);
const grossPerformanceFromSellWithCurrencyEffect = const grossPerformanceFromSellWithCurrencyEffect =
order.type === ActivityType.SELL order.type === 'SELL'
? order.unitPriceInBaseCurrencyWithCurrencyEffect ? order.unitPriceInBaseCurrencyWithCurrencyEffect
.minus(lastAveragePriceWithCurrencyEffect) .minus(lastAveragePriceWithCurrencyEffect)
.mul(order.quantity) .mul(order.quantity)

18
apps/client/src/app/services/import-activities.service.ts

@ -5,7 +5,7 @@ import { parseDate as parseDateHelper } from '@ghostfolio/common/helper';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Account, DataSource, Type } from '@prisma/client'; import { Account, DataSource, Type as ActivityType } from '@prisma/client';
import { isFinite } from 'lodash'; import { isFinite } from 'lodash';
import { parse as csvToJson } from 'papaparse'; import { parse as csvToJson } from 'papaparse';
import { EMPTY } from 'rxjs'; import { EMPTY } from 'rxjs';
@ -328,26 +328,26 @@ export class ImportActivitiesService {
content: any[]; content: any[];
index: number; index: number;
item: any; item: any;
}) { }): ActivityType {
item = this.lowercaseKeys(item); item = this.lowercaseKeys(item);
for (const key of ImportActivitiesService.TYPE_KEYS) { for (const key of ImportActivitiesService.TYPE_KEYS) {
if (item[key]) { if (item[key]) {
switch (item[key].toLowerCase()) { switch (item[key].toLowerCase()) {
case 'buy': case 'buy':
return Type.BUY; return 'BUY';
case 'dividend': case 'dividend':
return Type.DIVIDEND; return 'DIVIDEND';
case 'fee': case 'fee':
return Type.FEE; return 'FEE';
case 'interest': case 'interest':
return Type.INTEREST; return 'INTEREST';
case 'item': case 'item':
return Type.ITEM; return 'ITEM';
case 'liability': case 'liability':
return Type.LIABILITY; return 'LIABILITY';
case 'sell': case 'sell':
return Type.SELL; return 'SELL';
default: default:
break; break;
} }

Loading…
Cancel
Save