Browse Source

Feature/respect account currency in exchange rate data service (#391)

* Respect the accounts' currencies

* Update changelog
pull/392/head
Thomas Kaul 3 years ago
committed by GitHub
parent
commit
39d9828f9f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 42
      apps/api/src/services/exchange-rate-data.service.ts

1
CHANGELOG.md

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed the navigation to always show the portfolio page - Changed the navigation to always show the portfolio page
- Migrated the data type of currencies from `enum` to `string` in the database - Migrated the data type of currencies from `enum` to `string` in the database
- Supported unlimited currencies (instead of `CHF`, `EUR`, `GBP` and `USD`) - Supported unlimited currencies (instead of `CHF`, `EUR`, `GBP` and `USD`)
- Respected the accounts' currencies in the exchange rate service
### Fixed ### Fixed

42
apps/api/src/services/exchange-rate-data.service.ts

@ -168,28 +168,34 @@ export class ExchangeRateDataService {
private async prepareCurrencies(): Promise<string[]> { private async prepareCurrencies(): Promise<string[]> {
const currencies: string[] = []; const currencies: string[] = [];
const settings = await this.prismaService.settings.findMany({ (
distinct: ['currency'], await this.prismaService.account.findMany({
orderBy: [{ currency: 'asc' }], distinct: ['currency'],
select: { currency: true } orderBy: [{ currency: 'asc' }],
}); select: { currency: true }
})
settings.forEach((settingsItem) => { ).forEach((account) => {
if (settingsItem.currency) { currencies.push(account.currency);
currencies.push(settingsItem.currency);
}
}); });
const symbolProfiles = await this.prismaService.symbolProfile.findMany({ (
distinct: ['currency'], await this.prismaService.settings.findMany({
orderBy: [{ currency: 'asc' }], distinct: ['currency'],
select: { currency: true } orderBy: [{ currency: 'asc' }],
select: { currency: true }
})
).forEach((userSettings) => {
currencies.push(userSettings.currency);
}); });
symbolProfiles.forEach((symbolProfile) => { (
if (symbolProfile.currency) { await this.prismaService.symbolProfile.findMany({
currencies.push(symbolProfile.currency); distinct: ['currency'],
} orderBy: [{ currency: 'asc' }],
select: { currency: true }
})
).forEach((symbolProfile) => {
currencies.push(symbolProfile.currency);
}); });
return uniq(currencies).sort(); return uniq(currencies).sort();

Loading…
Cancel
Save