Browse Source

Compose exchange rates dynamically

pull/387/head
Thomas 4 years ago
parent
commit
4bc98b1921
  1. 44
      apps/api/src/app/admin/admin.service.ts

44
apps/api/src/app/admin/admin.service.ts

@ -3,6 +3,7 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration.ser
import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service'; import { DataGatheringService } from '@ghostfolio/api/services/data-gathering.service';
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { baseCurrency } from '@ghostfolio/common/config';
import { AdminData } from '@ghostfolio/common/interfaces'; import { AdminData } from '@ghostfolio/common/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { differenceInDays } from 'date-fns'; import { differenceInDays } from 'date-fns';
@ -19,33 +20,22 @@ export class AdminService {
public async get(): Promise<AdminData> { public async get(): Promise<AdminData> {
return { return {
exchangeRates: [ exchangeRates: this.exchangeRateDataService
{ .getCurrencies()
label1: 'EUR', .filter((currency) => {
label2: 'CHF', return currency !== baseCurrency;
value: await this.exchangeRateDataService.toCurrency(1, 'EUR', 'CHF') })
}, .map((currency) => {
{ return {
label1: 'GBP', label1: baseCurrency,
label2: 'CHF', label2: currency,
value: await this.exchangeRateDataService.toCurrency(1, 'GBP', 'CHF') value: this.exchangeRateDataService.toCurrency(
}, 1,
{ baseCurrency,
label1: 'USD', currency
label2: 'CHF', )
value: await this.exchangeRateDataService.toCurrency(1, 'USD', 'CHF') };
}, }),
{
label1: 'USD',
label2: 'EUR',
value: await this.exchangeRateDataService.toCurrency(1, 'USD', 'EUR')
},
{
label1: 'USD',
label2: 'GBP',
value: await this.exchangeRateDataService.toCurrency(1, 'USD', 'GBP')
}
],
lastDataGathering: await this.getLastDataGathering(), lastDataGathering: await this.getLastDataGathering(),
transactionCount: await this.prismaService.order.count(), transactionCount: await this.prismaService.order.count(),
userCount: await this.prismaService.user.count(), userCount: await this.prismaService.user.count(),

Loading…
Cancel
Save