|
@ -5,7 +5,12 @@ import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; |
|
|
import { resetHours } from '@ghostfolio/common/helper'; |
|
|
import { resetHours } from '@ghostfolio/common/helper'; |
|
|
import { UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { UniqueAsset } from '@ghostfolio/common/interfaces'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { DataSource, MarketData, Prisma } from '@prisma/client'; |
|
|
import { |
|
|
|
|
|
DataSource, |
|
|
|
|
|
MarketData, |
|
|
|
|
|
MarketDataState, |
|
|
|
|
|
Prisma |
|
|
|
|
|
} from '@prisma/client'; |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class MarketDataService { |
|
|
export class MarketDataService { |
|
@ -92,7 +97,9 @@ export class MarketDataService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async updateMarketData(params: { |
|
|
public async updateMarketData(params: { |
|
|
data: { dataSource: DataSource } & UpdateMarketDataDto; |
|
|
data: { |
|
|
|
|
|
state: MarketDataState; |
|
|
|
|
|
} & UpdateMarketDataDto; |
|
|
where: Prisma.MarketDataWhereUniqueInput; |
|
|
where: Prisma.MarketDataWhereUniqueInput; |
|
|
}): Promise<MarketData> { |
|
|
}): Promise<MarketData> { |
|
|
const { data, where } = params; |
|
|
const { data, where } = params; |
|
@ -100,12 +107,13 @@ export class MarketDataService { |
|
|
return this.prismaService.marketData.upsert({ |
|
|
return this.prismaService.marketData.upsert({ |
|
|
where, |
|
|
where, |
|
|
create: { |
|
|
create: { |
|
|
dataSource: data.dataSource, |
|
|
dataSource: where.dataSource_date_symbol.dataSource, |
|
|
date: where.dataSource_date_symbol.date, |
|
|
date: where.dataSource_date_symbol.date, |
|
|
marketPrice: data.marketPrice, |
|
|
marketPrice: data.marketPrice, |
|
|
|
|
|
state: data.state, |
|
|
symbol: where.dataSource_date_symbol.symbol |
|
|
symbol: where.dataSource_date_symbol.symbol |
|
|
}, |
|
|
}, |
|
|
update: { marketPrice: data.marketPrice } |
|
|
update: { marketPrice: data.marketPrice, state: data.state } |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -119,16 +127,18 @@ export class MarketDataService { |
|
|
data: Prisma.MarketDataUpdateInput[]; |
|
|
data: Prisma.MarketDataUpdateInput[]; |
|
|
}): Promise<MarketData[]> { |
|
|
}): Promise<MarketData[]> { |
|
|
const upsertPromises = data.map( |
|
|
const upsertPromises = data.map( |
|
|
({ dataSource, date, marketPrice, symbol }) => { |
|
|
({ dataSource, date, marketPrice, symbol, state }) => { |
|
|
return this.prismaService.marketData.upsert({ |
|
|
return this.prismaService.marketData.upsert({ |
|
|
create: { |
|
|
create: { |
|
|
dataSource: <DataSource>dataSource, |
|
|
dataSource: <DataSource>dataSource, |
|
|
date: <Date>date, |
|
|
date: <Date>date, |
|
|
marketPrice: <number>marketPrice, |
|
|
marketPrice: <number>marketPrice, |
|
|
|
|
|
state: <MarketDataState>state, |
|
|
symbol: <string>symbol |
|
|
symbol: <string>symbol |
|
|
}, |
|
|
}, |
|
|
update: { |
|
|
update: { |
|
|
marketPrice: <number>marketPrice |
|
|
marketPrice: <number>marketPrice, |
|
|
|
|
|
state: <MarketDataState>state |
|
|
}, |
|
|
}, |
|
|
where: { |
|
|
where: { |
|
|
dataSource_date_symbol: { |
|
|
dataSource_date_symbol: { |
|
|