From 7d70cd66436329e9ca8fa1db507dbd3848a0fba6 Mon Sep 17 00:00:00 2001 From: Manushreshta B L Date: Thu, 26 Oct 2023 02:10:08 +0530 Subject: [PATCH] Provided support for Scraper Configuration. --- apps/api/src/app/admin/admin.controller.ts | 2 +- .../data-gathering/data-gathering.service.ts | 10 ++++++--- .../asset-profile-dialog.component.ts | 11 ++++++++++ .../asset-profile-dialog.html | 22 ++++++++++++++----- apps/client/src/app/services/admin.service.ts | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/apps/api/src/app/admin/admin.controller.ts b/apps/api/src/app/admin/admin.controller.ts index a19b17d4a..ab48ff5cc 100644 --- a/apps/api/src/app/admin/admin.controller.ts +++ b/apps/api/src/app/admin/admin.controller.ts @@ -221,7 +221,7 @@ export class AdminController { @Param('dataSource') dataSource: DataSource, @Param('dateString') dateString: string, @Param('symbol') symbol: string - ): Promise { + ): Promise { if ( !hasPermission( this.request.user.permissions, diff --git a/apps/api/src/services/data-gathering/data-gathering.service.ts b/apps/api/src/services/data-gathering/data-gathering.service.ts index 78531b745..421e0a176 100644 --- a/apps/api/src/services/data-gathering/data-gathering.service.ts +++ b/apps/api/src/services/data-gathering/data-gathering.service.ts @@ -15,6 +15,7 @@ import { import { DATE_FORMAT, getAssetProfileIdentifier, + getYesterday, resetHours } from '@ghostfolio/common/helper'; import { BenchmarkProperty, UniqueAsset } from '@ghostfolio/common/interfaces'; @@ -96,8 +97,9 @@ export class DataGatheringService { date ); - const marketPrice = - historicalData[symbol][format(date, DATE_FORMAT)].marketPrice; + var marketPrice = + historicalData[symbol]?.[format(getYesterday(), DATE_FORMAT)] + .marketPrice; if (marketPrice) { return await this.prismaService.marketData.upsert({ @@ -114,7 +116,9 @@ export class DataGatheringService { } catch (error) { Logger.error(error, 'DataGatheringService'); } finally { - return undefined; + if (dataSource === 'MANUAL' && marketPrice !== undefined) + return marketPrice; + else return undefined; } } diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index c5c2db17a..9d205d127 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -240,6 +240,17 @@ export class AssetProfileDialog implements OnDestroy, OnInit { }); } + public onTestScraper(symbol: string) { + const today = new Date(); + this.adminService + .gatherSymbol({ dataSource: 'MANUAL', date: today, symbol }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((response) => { + if (response !== null) alert('Current Market Price is: ' + response); + else alert('Please try again.'); + }); + } + public onUnsetBenchmark({ dataSource, symbol }: UniqueAsset) { this.dataService .deleteBenchmark({ dataSource, symbol }) diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html index 755768209..d5adc066e 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html @@ -235,12 +235,22 @@
Scraper Configuration - +
+ + +
diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts index 4965c6067..0ca75fe2d 100644 --- a/apps/client/src/app/services/admin.service.ts +++ b/apps/client/src/app/services/admin.service.ts @@ -182,7 +182,7 @@ export class AdminService { url = `${url}/${format(date, DATE_FORMAT)}`; } - return this.http.post(url, {}); + return this.http.post(url, {}); } public fetchSymbolForDate({