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
});
},
getRange: (
dateRangeEnd: Date,
dateRangeStart: Date,
symbol: string
) => {
getRange: ({
dateRangeEnd,
dateRangeStart,
symbols
}: {
dateRangeEnd: Date;
dateRangeStart: Date;
symbols: string[];
}) => {
return Promise.resolve<MarketData[]>([
{
date: dateRangeStart,
symbol,
symbol: symbols[0],
createdAt: dateRangeStart,
id: '8fa48fde-f397-4b0d-adbc-fb940e830e6d',
marketPrice: 1841.823902
},
{
date: dateRangeEnd,
symbol,
symbol: symbols[0],
createdAt: dateRangeEnd,
id: '082d6893-df27-4c91-8a5d-092e84315b56',
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 {
ExchangeRateDataService: jest.fn().mockImplementation(() => {
return {
@ -101,10 +105,10 @@ describe('CurrentRateService', () => {
it('getValues', async () => {
expect(
await currentRateService.getValues({
currency: Currency.USD,
currencies: { AMZN: Currency.USD },
dateRangeEnd: new Date(Date.UTC(2020, 0, 2, 0, 0, 0)),
dateRangeStart: new Date(Date.UTC(2020, 0, 1, 0, 0, 0)),
symbol: 'AMZN',
symbols: ['AMZN'],
userCurrency: Currency.CHF
})
).toMatchObject([

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

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

Loading…
Cancel
Save