change getValues to multiple symbols

pull/239/head
Valentin Zickner 3 years ago committed by Thomas
parent fbc9269abf
commit c88ad2c225

@ -18,22 +18,26 @@ jest.mock('./market-data.service', () => {
marketPrice: 1847.839966 marketPrice: 1847.839966
}); });
}, },
getRange: ( getRange: ({
dateRangeEnd: Date, dateRangeEnd,
dateRangeStart: Date, dateRangeStart,
symbol: string symbols
) => { }: {
dateRangeEnd: Date;
dateRangeStart: Date;
symbols: string[];
}) => {
return Promise.resolve<MarketData[]>([ return Promise.resolve<MarketData[]>([
{ {
date: dateRangeStart, date: dateRangeStart,
symbol, symbol: symbols[0],
createdAt: dateRangeStart, createdAt: dateRangeStart,
id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d', id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d',
marketPrice: 1841.823902 marketPrice: 1841.823902
}, },
{ {
date: dateRangeEnd, date: dateRangeEnd,
symbol, symbol: symbols[0],
createdAt: dateRangeEnd, createdAt: dateRangeEnd,
id: '082d6893-df27-4c91-8a5d-092e84315b56', id: '082d6893-df27-4c91-8a5d-092e84315b56',
marketPrice: 1847.839966 marketPrice: 1847.839966
@ -45,7 +49,7 @@ jest.mock('./market-data.service', () => {
}; };
}); });
jest.mock('../../services/exchange-rate-data.service', () => { jest.mock('@ghostfolio/api/services/exchange-rate-data.service', () => {
return { return {
ExchangeRateDataService: jest.fn().mockImplementation(() => { ExchangeRateDataService: jest.fn().mockImplementation(() => {
return { return {
@ -101,10 +105,10 @@ describe('CurrentRateService', () => {
it('getValues', async () => { it('getValues', async () => {
expect( expect(
await currentRateService.getValues({ await currentRateService.getValues({
currency: Currency.USD, currencies: { AMZN: Currency.USD },
dateRangeEnd: new Date(Date.UTC(2020, 0, 2, 0, 0, 0)), dateRangeEnd: new Date(Date.UTC(2020, 0, 2, 0, 0, 0)),
dateRangeStart: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)), dateRangeStart: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)),
symbol: 'AMZN', symbols: ['AMZN'],
userCurrency: Currency.CHF userCurrency: Currency.CHF
}) })
).toMatchObject([ ).toMatchObject([

@ -49,16 +49,16 @@ export class CurrentRateService {
} }
public async getValues({ public async getValues({
currency, currencies,
dateRangeEnd, dateRangeEnd,
dateRangeStart, dateRangeStart,
symbol, symbols,
userCurrency userCurrency
}: GetValuesParams): Promise<GetValueObject[]> { }: GetValuesParams): Promise<GetValueObject[]> {
const marketData = await this.marketDataService.getRange({ const marketData = await this.marketDataService.getRange({
dateRangeEnd, dateRangeEnd,
dateRangeStart, dateRangeStart,
symbol symbols
}); });
if (marketData) { if (marketData) {
@ -67,7 +67,7 @@ export class CurrentRateService {
date: marketDataItem.date, date: marketDataItem.date,
marketPrice: this.exchangeRateDataService.toCurrency( marketPrice: this.exchangeRateDataService.toCurrency(
marketDataItem.marketPrice, marketDataItem.marketPrice,
currency, currencies[marketDataItem.symbol],
userCurrency userCurrency
) )
}; };
@ -75,7 +75,7 @@ export class CurrentRateService {
} }
throw new Error( throw new Error(
`Values not found for ${symbol} from ${resetHours( `Values not found for symbols ${symbols.join(', ')} from ${resetHours(
dateRangeStart dateRangeStart
)} to ${resetHours(dateRangeEnd)}` )} to ${resetHours(dateRangeEnd)}`
); );
@ -92,8 +92,8 @@ export interface GetValueParams {
export interface GetValuesParams { export interface GetValuesParams {
dateRangeEnd: Date; dateRangeEnd: Date;
dateRangeStart: Date; dateRangeStart: Date;
symbol: string; symbols: string[];
currency: Currency; currencies: { [symbol: string]: Currency };
userCurrency: Currency; userCurrency: Currency;
} }

@ -26,11 +26,11 @@ export class MarketDataService {
public async getRange({ public async getRange({
dateRangeEnd, dateRangeEnd,
dateRangeStart, dateRangeStart,
symbol symbols
}: { }: {
dateRangeEnd: Date; dateRangeEnd: Date;
dateRangeStart: Date; dateRangeStart: Date;
symbol: string; symbols: string[];
}): Promise<MarketData[]> { }): Promise<MarketData[]> {
return await this.prisma.marketData.findMany({ return await this.prisma.marketData.findMany({
where: { where: {
@ -38,7 +38,9 @@ export class MarketDataService {
gte: dateRangeStart, gte: dateRangeStart,
lt: endOfDay(dateRangeEnd) lt: endOfDay(dateRangeEnd)
}, },
symbol symbol: {
in: symbols
}
} }
}); });
} }

Loading…
Cancel
Save