Browse Source

Changes attempted as per request.

pull/2546/head
Manushreshta B L 2 years ago
parent
commit
b5d64b0c30
  1. 6
      apps/api/src/app/admin/admin.controller.ts
  2. 24
      apps/api/src/services/data-gathering/data-gathering.service.ts
  3. 14
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  4. 6
      apps/client/src/app/services/admin.service.ts

6
apps/api/src/app/admin/admin.controller.ts

@ -220,8 +220,9 @@ export class AdminController {
public async gatherSymbolForDate( public async gatherSymbolForDate(
@Param('dataSource') dataSource: DataSource, @Param('dataSource') dataSource: DataSource,
@Param('dateString') dateString: string, @Param('dateString') dateString: string,
@Param('symbol') symbol: string @Param('symbol') symbol: string,
): Promise<MarketData | number> { @Query('dryRun') isDryRun?: boolean
): Promise<MarketData> {
if ( if (
!hasPermission( !hasPermission(
this.request.user.permissions, this.request.user.permissions,
@ -246,6 +247,7 @@ export class AdminController {
return this.dataGatheringService.gatherSymbolForDate({ return this.dataGatheringService.gatherSymbolForDate({
dataSource, dataSource,
date, date,
isDryRun,
symbol symbol
}); });
} }

24
apps/api/src/services/data-gathering/data-gathering.service.ts

@ -21,7 +21,7 @@ import {
import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces';
import { InjectQueue } from '@nestjs/bull'; import { InjectQueue } from '@nestjs/bull';
import { Inject, Injectable, Logger } from '@nestjs/common'; import { Inject, Injectable, Logger } from '@nestjs/common';
import { DataSource } from '@prisma/client'; import { DataSource, MarketDataState } from '@prisma/client';
import { JobOptions, Queue } from 'bull'; import { JobOptions, Queue } from 'bull';
import { format, min, subDays, subYears } from 'date-fns'; import { format, min, subDays, subYears } from 'date-fns';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
@ -84,10 +84,12 @@ export class DataGatheringService {
public async gatherSymbolForDate({ public async gatherSymbolForDate({
dataSource, dataSource,
date, date,
isDryRun,
symbol symbol
}: { }: {
dataSource: DataSource; dataSource: DataSource;
date: Date; date: Date;
isDryRun: boolean;
symbol: string; symbol: string;
}) { }) {
try { try {
@ -96,11 +98,23 @@ export class DataGatheringService {
date, date,
date date
); );
const marketPrice =
var marketPrice =
historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)] historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)]
.marketPrice; .marketPrice;
if (isDryRun) {
const date = new Date();
return {
dataSource,
date,
marketPrice,
symbol,
createdAt: null,
id: null,
state: MarketDataState.INTRADAY
};
}
if (marketPrice) { if (marketPrice) {
return await this.prismaService.marketData.upsert({ return await this.prismaService.marketData.upsert({
create: { create: {
@ -116,9 +130,7 @@ export class DataGatheringService {
} catch (error) { } catch (error) {
Logger.error(error, 'DataGatheringService'); Logger.error(error, 'DataGatheringService');
} finally { } finally {
if (dataSource === 'MANUAL' && marketPrice !== undefined) return undefined;
return marketPrice;
else return undefined;
} }
} }

14
apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts

@ -243,11 +243,19 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
public onTestScraper(symbol: string) { public onTestScraper(symbol: string) {
const today = new Date(); const today = new Date();
this.adminService this.adminService
.gatherSymbol({ dataSource: 'MANUAL', date: today, symbol }) .gatherSymbol({
dataSource: 'MANUAL',
date: today,
isDryRun: true,
symbol
})
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe((response) => { .subscribe((response) => {
if (response !== null) alert('Current Market Price is: ' + response); if (response !== null) {
else alert('Please try again.'); alert($localize`Please try again.`);
} else {
alert($localize`Current Market Price is:` + ' ' + response);
}
}); });
} }

6
apps/client/src/app/services/admin.service.ts

@ -175,14 +175,16 @@ export class AdminService {
symbol symbol
}: UniqueAsset & { }: UniqueAsset & {
date?: Date; date?: Date;
} & {
isDryRun?: boolean;
}) { }) {
let url = `/api/v1/admin/gather/${dataSource}/${symbol}`; let url = `/api/v1/admin/gather/${dataSource}/${symbol}`;
if (date) { if (date) {
url = `${url}/${format(date, DATE_FORMAT)}`; url = `${url}/${format(date, DATE_FORMAT)}?dryRun=true`;
} }
return this.http.post<MarketData | number | void>(url, {}); return this.http.post<MarketData | void>(url, {});
} }
public fetchSymbolForDate({ public fetchSymbolForDate({

Loading…
Cancel
Save