From 0aedd37b91739d0951796b16643a29cedfeb6041 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 3 Aug 2024 21:37:39 +0200 Subject: [PATCH] Refactoring --- .../portfolio/current-rate.service.spec.ts | 14 +++++------ .../src/app/portfolio/current-rate.service.ts | 4 ++-- apps/api/src/app/symbol/symbol.service.ts | 6 ++--- .../exchange-rate-data.service.ts | 24 +++++++++---------- .../market-data/market-data.service.ts | 10 ++++---- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/apps/api/src/app/portfolio/current-rate.service.spec.ts b/apps/api/src/app/portfolio/current-rate.service.spec.ts index b334754e3..c86dde448 100644 --- a/apps/api/src/app/portfolio/current-rate.service.spec.ts +++ b/apps/api/src/app/portfolio/current-rate.service.spec.ts @@ -24,32 +24,32 @@ jest.mock('@ghostfolio/api/services/market-data/market-data.service', () => { }); }, getRange: ({ + assetProfileIdentifiers, dateRangeEnd, - dateRangeStart, - uniqueAssets + dateRangeStart }: { + assetProfileIdentifiers: AssetProfileIdentifier[]; dateRangeEnd: Date; dateRangeStart: Date; - uniqueAssets: AssetProfileIdentifier[]; }) => { return Promise.resolve([ { createdAt: dateRangeStart, - dataSource: uniqueAssets[0].dataSource, + dataSource: assetProfileIdentifiers[0].dataSource, date: dateRangeStart, id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d', marketPrice: 1841.823902, state: 'CLOSE', - symbol: uniqueAssets[0].symbol + symbol: assetProfileIdentifiers[0].symbol }, { createdAt: dateRangeEnd, - dataSource: uniqueAssets[0].dataSource, + dataSource: assetProfileIdentifiers[0].dataSource, date: dateRangeEnd, id: '082d6893-df27-4c91-8a5d-092e84315b56', marketPrice: 1847.839966, state: 'CLOSE', - symbol: uniqueAssets[0].symbol + symbol: assetProfileIdentifiers[0].symbol } ]); } diff --git a/apps/api/src/app/portfolio/current-rate.service.ts b/apps/api/src/app/portfolio/current-rate.service.ts index fc0fab387..24119162d 100644 --- a/apps/api/src/app/portfolio/current-rate.service.ts +++ b/apps/api/src/app/portfolio/current-rate.service.ts @@ -88,8 +88,8 @@ export class CurrentRateService { promises.push( this.marketDataService .getRange({ - dateQuery, - uniqueAssets: assetProfileIdentifiers + assetProfileIdentifiers, + dateQuery }) .then((data) => { return data.map(({ dataSource, date, marketPrice, symbol }) => { diff --git a/apps/api/src/app/symbol/symbol.service.ts b/apps/api/src/app/symbol/symbol.service.ts index 90259a776..2baca18dd 100644 --- a/apps/api/src/app/symbol/symbol.service.ts +++ b/apps/api/src/app/symbol/symbol.service.ts @@ -40,13 +40,13 @@ export class SymbolService { const days = includeHistoricalData; const marketData = await this.marketDataService.getRange({ - dateQuery: { gte: subDays(new Date(), days) }, - uniqueAssets: [ + assetProfileIdentifiers: [ { dataSource: dataGatheringItem.dataSource, symbol: dataGatheringItem.symbol } - ] + ], + dateQuery: { gte: subDays(new Date(), days) } }); historicalData = marketData.map(({ date, marketPrice: value }) => { diff --git a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts index 29d199ed7..1f08034cd 100644 --- a/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts +++ b/apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts @@ -361,13 +361,13 @@ export class ExchangeRateDataService { const symbol = `${currencyFrom}${currencyTo}`; const marketData = await this.marketDataService.getRange({ - dateQuery: { gte: startDate, lt: endDate }, - uniqueAssets: [ + assetProfileIdentifiers: [ { dataSource, symbol } - ] + ], + dateQuery: { gte: startDate, lt: endDate } }); if (marketData?.length > 0) { @@ -392,13 +392,13 @@ export class ExchangeRateDataService { } } else { const marketData = await this.marketDataService.getRange({ - dateQuery: { gte: startDate, lt: endDate }, - uniqueAssets: [ + assetProfileIdentifiers: [ { dataSource, symbol: `${DEFAULT_CURRENCY}${currencyFrom}` } - ] + ], + dateQuery: { gte: startDate, lt: endDate } }); for (const { date, marketPrice } of marketData) { @@ -415,16 +415,16 @@ export class ExchangeRateDataService { } } else { const marketData = await this.marketDataService.getRange({ - dateQuery: { - gte: startDate, - lt: endDate - }, - uniqueAssets: [ + assetProfileIdentifiers: [ { dataSource, symbol: `${DEFAULT_CURRENCY}${currencyTo}` } - ] + ], + dateQuery: { + gte: startDate, + lt: endDate + } }); for (const { date, marketPrice } of marketData) { diff --git a/apps/api/src/services/market-data/market-data.service.ts b/apps/api/src/services/market-data/market-data.service.ts index a5137aeeb..09f591b9e 100644 --- a/apps/api/src/services/market-data/market-data.service.ts +++ b/apps/api/src/services/market-data/market-data.service.ts @@ -59,11 +59,11 @@ export class MarketDataService { } public async getRange({ - dateQuery, - uniqueAssets + assetProfileIdentifiers, + dateQuery }: { + assetProfileIdentifiers: AssetProfileIdentifier[]; dateQuery: DateQuery; - uniqueAssets: AssetProfileIdentifier[]; }): Promise { return this.prismaService.marketData.findMany({ orderBy: [ @@ -76,13 +76,13 @@ export class MarketDataService { ], where: { dataSource: { - in: uniqueAssets.map(({ dataSource }) => { + in: assetProfileIdentifiers.map(({ dataSource }) => { return dataSource; }) }, date: dateQuery, symbol: { - in: uniqueAssets.map(({ symbol }) => { + in: assetProfileIdentifiers.map(({ symbol }) => { return symbol; }) }