* introduce basic module structure for data provider * introduce DataGatheringModule * introduce ExchangeRateDataModule * introduce ImpersonationModule * move RulesService * cleanup portfolio module * Sort imports Co-authored-by: Valentin Zickner <github@zickner.ch> Co-authored-by: Thomas <4159106+dtslvr@users.noreply.github.com>
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
import { PrismaService } from '@ghostfolio/api/services/prisma.service';
|
|
import { resetHours } from '@ghostfolio/common/helper';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { MarketData } from '@prisma/client';
|
|
|
|
import { DateQuery } from './interfaces/date-query.interface';
|
|
|
|
@Injectable()
|
|
export class MarketDataService {
|
|
public constructor(private readonly prismaService: PrismaService) {}
|
|
|
|
public async get({
|
|
date,
|
|
symbol
|
|
}: {
|
|
date: Date;
|
|
symbol: string;
|
|
}): Promise<MarketData> {
|
|
return await this.prismaService.marketData.findFirst({
|
|
where: {
|
|
symbol,
|
|
date: resetHours(date)
|
|
}
|
|
});
|
|
}
|
|
|
|
public async getRange({
|
|
dateQuery,
|
|
symbols
|
|
}: {
|
|
dateQuery: DateQuery;
|
|
symbols: string[];
|
|
}): Promise<MarketData[]> {
|
|
return await this.prismaService.marketData.findMany({
|
|
orderBy: [
|
|
{
|
|
date: 'asc'
|
|
},
|
|
{
|
|
symbol: 'asc'
|
|
}
|
|
],
|
|
where: {
|
|
date: dateQuery,
|
|
symbol: {
|
|
in: symbols
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|