Browse Source

Refactoring

pull/3636/head
Thomas Kaul 1 year ago
parent
commit
0aedd37b91
  1. 14
      apps/api/src/app/portfolio/current-rate.service.spec.ts
  2. 4
      apps/api/src/app/portfolio/current-rate.service.ts
  3. 6
      apps/api/src/app/symbol/symbol.service.ts
  4. 24
      apps/api/src/services/exchange-rate-data/exchange-rate-data.service.ts
  5. 10
      apps/api/src/services/market-data/market-data.service.ts

14
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: ({ getRange: ({
assetProfileIdentifiers,
dateRangeEnd, dateRangeEnd,
dateRangeStart, dateRangeStart
uniqueAssets
}: { }: {
assetProfileIdentifiers: AssetProfileIdentifier[];
dateRangeEnd: Date; dateRangeEnd: Date;
dateRangeStart: Date; dateRangeStart: Date;
uniqueAssets: AssetProfileIdentifier[];
}) => { }) => {
return Promise.resolve<MarketData[]>([ return Promise.resolve<MarketData[]>([
{ {
createdAt: dateRangeStart, createdAt: dateRangeStart,
dataSource: uniqueAssets[0].dataSource, dataSource: assetProfileIdentifiers[0].dataSource,
date: dateRangeStart, date: dateRangeStart,
id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d', id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d',
marketPrice: 1841.823902, marketPrice: 1841.823902,
state: 'CLOSE', state: 'CLOSE',
symbol: uniqueAssets[0].symbol symbol: assetProfileIdentifiers[0].symbol
}, },
{ {
createdAt: dateRangeEnd, createdAt: dateRangeEnd,
dataSource: uniqueAssets[0].dataSource, dataSource: assetProfileIdentifiers[0].dataSource,
date: dateRangeEnd, date: dateRangeEnd,
id: '082d6893-df27-4c91-8a5d-092e84315b56', id: '082d6893-df27-4c91-8a5d-092e84315b56',
marketPrice: 1847.839966, marketPrice: 1847.839966,
state: 'CLOSE', state: 'CLOSE',
symbol: uniqueAssets[0].symbol symbol: assetProfileIdentifiers[0].symbol
} }
]); ]);
} }

4
apps/api/src/app/portfolio/current-rate.service.ts

@ -88,8 +88,8 @@ export class CurrentRateService {
promises.push( promises.push(
this.marketDataService this.marketDataService
.getRange({ .getRange({
dateQuery, assetProfileIdentifiers,
uniqueAssets: assetProfileIdentifiers dateQuery
}) })
.then((data) => { .then((data) => {
return data.map(({ dataSource, date, marketPrice, symbol }) => { return data.map(({ dataSource, date, marketPrice, symbol }) => {

6
apps/api/src/app/symbol/symbol.service.ts

@ -40,13 +40,13 @@ export class SymbolService {
const days = includeHistoricalData; const days = includeHistoricalData;
const marketData = await this.marketDataService.getRange({ const marketData = await this.marketDataService.getRange({
dateQuery: { gte: subDays(new Date(), days) }, assetProfileIdentifiers: [
uniqueAssets: [
{ {
dataSource: dataGatheringItem.dataSource, dataSource: dataGatheringItem.dataSource,
symbol: dataGatheringItem.symbol symbol: dataGatheringItem.symbol
} }
] ],
dateQuery: { gte: subDays(new Date(), days) }
}); });
historicalData = marketData.map(({ date, marketPrice: value }) => { historicalData = marketData.map(({ date, marketPrice: value }) => {

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

@ -361,13 +361,13 @@ export class ExchangeRateDataService {
const symbol = `${currencyFrom}${currencyTo}`; const symbol = `${currencyFrom}${currencyTo}`;
const marketData = await this.marketDataService.getRange({ const marketData = await this.marketDataService.getRange({
dateQuery: { gte: startDate, lt: endDate }, assetProfileIdentifiers: [
uniqueAssets: [
{ {
dataSource, dataSource,
symbol symbol
} }
] ],
dateQuery: { gte: startDate, lt: endDate }
}); });
if (marketData?.length > 0) { if (marketData?.length > 0) {
@ -392,13 +392,13 @@ export class ExchangeRateDataService {
} }
} else { } else {
const marketData = await this.marketDataService.getRange({ const marketData = await this.marketDataService.getRange({
dateQuery: { gte: startDate, lt: endDate }, assetProfileIdentifiers: [
uniqueAssets: [
{ {
dataSource, dataSource,
symbol: `${DEFAULT_CURRENCY}${currencyFrom}` symbol: `${DEFAULT_CURRENCY}${currencyFrom}`
} }
] ],
dateQuery: { gte: startDate, lt: endDate }
}); });
for (const { date, marketPrice } of marketData) { for (const { date, marketPrice } of marketData) {
@ -415,16 +415,16 @@ export class ExchangeRateDataService {
} }
} else { } else {
const marketData = await this.marketDataService.getRange({ const marketData = await this.marketDataService.getRange({
dateQuery: { assetProfileIdentifiers: [
gte: startDate,
lt: endDate
},
uniqueAssets: [
{ {
dataSource, dataSource,
symbol: `${DEFAULT_CURRENCY}${currencyTo}` symbol: `${DEFAULT_CURRENCY}${currencyTo}`
} }
] ],
dateQuery: {
gte: startDate,
lt: endDate
}
}); });
for (const { date, marketPrice } of marketData) { for (const { date, marketPrice } of marketData) {

10
apps/api/src/services/market-data/market-data.service.ts

@ -59,11 +59,11 @@ export class MarketDataService {
} }
public async getRange({ public async getRange({
dateQuery, assetProfileIdentifiers,
uniqueAssets dateQuery
}: { }: {
assetProfileIdentifiers: AssetProfileIdentifier[];
dateQuery: DateQuery; dateQuery: DateQuery;
uniqueAssets: AssetProfileIdentifier[];
}): Promise<MarketData[]> { }): Promise<MarketData[]> {
return this.prismaService.marketData.findMany({ return this.prismaService.marketData.findMany({
orderBy: [ orderBy: [
@ -76,13 +76,13 @@ export class MarketDataService {
], ],
where: { where: {
dataSource: { dataSource: {
in: uniqueAssets.map(({ dataSource }) => { in: assetProfileIdentifiers.map(({ dataSource }) => {
return dataSource; return dataSource;
}) })
}, },
date: dateQuery, date: dateQuery,
symbol: { symbol: {
in: uniqueAssets.map(({ symbol }) => { in: assetProfileIdentifiers.map(({ symbol }) => {
return symbol; return symbol;
}) })
} }

Loading…
Cancel
Save