Bugfix/fix creation of historical data (#594)

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

* Update changelog
pull/595/head
Thomas Kaul 2 years ago committed by GitHub
parent e37a650c70
commit 438484879d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### 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
## 1.97.0 - 28.12.2021

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

@ -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 { PrismaService } from '@ghostfolio/api/services/prisma.service';
import { resetHours } from '@ghostfolio/common/helper';
import { Injectable } from '@nestjs/common';
import { MarketData, Prisma } from '@prisma/client';
import { DataSource, MarketData, Prisma } from '@prisma/client';
@Injectable()
export class MarketDataService {
@ -67,14 +68,20 @@ export class MarketDataService {
}
public async updateMarketData(params: {
data: Prisma.MarketDataUpdateInput;
data: { dataSource: DataSource } & UpdateMarketDataDto;
where: Prisma.MarketDataWhereUniqueInput;
}): Promise<MarketData> {
const { data, where } = params;
return this.prismaService.marketData.update({
data,
where
return this.prismaService.marketData.upsert({
where,
create: {
dataSource: data.dataSource,
date: where.date_symbol.date,
marketPrice: data.marketPrice,
symbol: where.date_symbol.symbol
},
update: { marketPrice: data.marketPrice }
});
}
}

Loading…
Cancel
Save