Bugfix/fix creation of historical data (#594)

* Fix creation of historical data (upsert instead of update)

* Update changelog
This commit is contained in:
Thomas Kaul 2021-12-29 17:03:37 +01:00 committed by GitHub
parent e37a650c70
commit 438484879d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the creation of historical data in the admin control panel (upsert instead of update)
- Fixed the scrolling issue in the position detail dialog on mobile - Fixed the scrolling issue in the position detail dialog on mobile
## 1.97.0 - 28.12.2021 ## 1.97.0 - 28.12.2021

View File

@ -215,7 +215,7 @@ export class AdminController {
const date = new Date(dateString); const date = new Date(dateString);
return this.marketDataService.updateMarketData({ return this.marketDataService.updateMarketData({
data, data: { ...data, dataSource },
where: { where: {
date_symbol: { date_symbol: {
date, date,

View File

@ -1,8 +1,9 @@
import { UpdateMarketDataDto } from '@ghostfolio/api/app/admin/update-market-data.dto';
import { DateQuery } from '@ghostfolio/api/app/portfolio/interfaces/date-query.interface'; import { DateQuery } from '@ghostfolio/api/app/portfolio/interfaces/date-query.interface';
import { PrismaService } from '@ghostfolio/api/services/prisma.service'; import { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { resetHours } from '@ghostfolio/common/helper'; import { resetHours } from '@ghostfolio/common/helper';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { MarketData, Prisma } from '@prisma/client'; import { DataSource, MarketData, Prisma } from '@prisma/client';
@Injectable() @Injectable()
export class MarketDataService { export class MarketDataService {
@ -67,14 +68,20 @@ export class MarketDataService {
} }
public async updateMarketData(params: { public async updateMarketData(params: {
data: Prisma.MarketDataUpdateInput; data: { dataSource: DataSource } & UpdateMarketDataDto;
where: Prisma.MarketDataWhereUniqueInput; where: Prisma.MarketDataWhereUniqueInput;
}): Promise<MarketData> { }): Promise<MarketData> {
const { data, where } = params; const { data, where } = params;
return this.prismaService.marketData.update({ return this.prismaService.marketData.upsert({
data, where,
where create: {
dataSource: data.dataSource,
date: where.date_symbol.date,
marketPrice: data.marketPrice,
symbol: where.date_symbol.symbol
},
update: { marketPrice: data.marketPrice }
}); });
} }
} }