Browse Source

Refactoring

pull/1769/head
Thomas 3 years ago
parent
commit
d44de35923
  1. 6
      apps/api/src/app/exchange-rate/exchange-rate.controller.ts
  2. 7
      apps/api/src/app/exchange-rate/exchange-rate.service.ts

6
apps/api/src/app/exchange-rate/exchange-rate.controller.ts

@ -25,13 +25,13 @@ export class ExchangeRateController {
): Promise<IDataProviderHistoricalResponse> { ): Promise<IDataProviderHistoricalResponse> {
const date = new Date(dateString); const date = new Date(dateString);
const { marketPrice } = await this.exchangeRateService.getExchangeRate({ const exchangeRate = await this.exchangeRateService.getExchangeRate({
date, date,
symbol symbol
}); });
if (marketPrice) { if (exchangeRate) {
return { marketPrice }; return { marketPrice: exchangeRate };
} }
throw new HttpException( throw new HttpException(

7
apps/api/src/app/exchange-rate/exchange-rate.service.ts

@ -1,5 +1,4 @@
import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data.service';
import { IDataProviderHistoricalResponse } from '@ghostfolio/api/services/interfaces/interfaces';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
@Injectable() @Injectable()
@ -14,16 +13,14 @@ export class ExchangeRateService {
}: { }: {
date: Date; date: Date;
symbol: string; symbol: string;
}): Promise<IDataProviderHistoricalResponse> { }): Promise<number> {
const [currency1, currency2] = symbol.split('-'); const [currency1, currency2] = symbol.split('-');
const marketPrice = await this.exchangeRateDataService.toCurrencyAtDate( return this.exchangeRateDataService.toCurrencyAtDate(
1, 1,
currency1, currency1,
currency2, currency2,
date date
); );
return { marketPrice };
} }
} }

Loading…
Cancel
Save