Browse Source

code review changes

pull/5335/head
Attila Cseh 2 weeks ago
parent
commit
7774a6333e
  1. 111
      apps/api/src/app/portfolio/portfolio.service.ts

111
apps/api/src/app/portfolio/portfolio.service.ts

@ -176,66 +176,73 @@ export class PortfolioService {
const userCurrency = this.request.user.settings.settings.baseCurrency; const userCurrency = this.request.user.settings.settings.baseCurrency;
return accounts.map((account) => { return Promise.all(
let dividendInBaseCurrency = 0; accounts.map(async (account) => {
let interestInBaseCurrency = 0; let dividendInBaseCurrency = 0;
let transactionCount = 0; let interestInBaseCurrency = 0;
let transactionCount = 0;
for (const { for (const {
isDraft, currency,
currency, date,
SymbolProfile, isDraft,
type, SymbolProfile,
unitPrice type,
} of account.activities) { unitPrice
switch (type) { } of account.activities) {
case ActivityType.DIVIDEND: switch (type) {
dividendInBaseCurrency += this.exchangeRateDataService.toCurrency( case ActivityType.DIVIDEND:
unitPrice, dividendInBaseCurrency +=
currency ?? SymbolProfile.currency, await this.exchangeRateDataService.toCurrencyAtDate(
userCurrency unitPrice,
); currency ?? SymbolProfile.currency,
break; userCurrency,
case ActivityType.INTEREST: date
interestInBaseCurrency += this.exchangeRateDataService.toCurrency( );
unitPrice, break;
currency ?? SymbolProfile.currency, case ActivityType.INTEREST:
userCurrency interestInBaseCurrency +=
); await this.exchangeRateDataService.toCurrencyAtDate(
break; unitPrice,
} currency ?? SymbolProfile.currency,
userCurrency,
date
);
break;
}
if (!isDraft) { if (!isDraft) {
transactionCount += 1; transactionCount += 1;
}
} }
}
const valueInBaseCurrency = const valueInBaseCurrency =
details.accounts[account.id]?.valueInBaseCurrency ?? 0; details.accounts[account.id]?.valueInBaseCurrency ?? 0;
const result = { const result = {
...account, ...account,
dividendInBaseCurrency, dividendInBaseCurrency,
interestInBaseCurrency, interestInBaseCurrency,
transactionCount, transactionCount,
valueInBaseCurrency,
allocationInPercentage: null, // TODO
balanceInBaseCurrency: this.exchangeRateDataService.toCurrency(
account.balance,
account.currency,
userCurrency
),
value: this.exchangeRateDataService.toCurrency(
valueInBaseCurrency, valueInBaseCurrency,
userCurrency, allocationInPercentage: null, // TODO
account.currency balanceInBaseCurrency: this.exchangeRateDataService.toCurrency(
) account.balance,
}; account.currency,
userCurrency
),
value: this.exchangeRateDataService.toCurrency(
valueInBaseCurrency,
userCurrency,
account.currency
)
};
delete result.activities; delete result.activities;
return result; return result;
}); })
);
} }
public async getAccountsWithAggregations({ public async getAccountsWithAggregations({

Loading…
Cancel
Save