From 4a2825840d1ae904dc7501bcb5fa453634b5d4b8 Mon Sep 17 00:00:00 2001 From: Manushreshta B L Date: Sun, 1 Oct 2023 20:03:16 +0530 Subject: [PATCH] Response to reviews --- .../src/app/benchmark/benchmark.controller.ts | 8 ++++++-- .../src/app/benchmark/benchmark.service.ts | 8 ++++---- .../asset-profile-dialog.component.ts | 20 +++++++++---------- .../asset-profile-dialog.module.ts | 2 +- apps/client/src/app/services/data.service.ts | 8 ++++---- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/apps/api/src/app/benchmark/benchmark.controller.ts b/apps/api/src/app/benchmark/benchmark.controller.ts index 4a87d73b2..960883fb1 100644 --- a/apps/api/src/app/benchmark/benchmark.controller.ts +++ b/apps/api/src/app/benchmark/benchmark.controller.ts @@ -10,6 +10,7 @@ import type { RequestWithUser } from '@ghostfolio/common/types'; import { Body, Controller, + Delete, Get, HttpException, Inject, @@ -95,9 +96,12 @@ export class BenchmarkController { } } - @Post('remove') + @Delete(':dataSource/:symbol') @UseGuards(AuthGuard('jwt')) - public async deleteBenchmark(@Body() { dataSource, symbol }: UniqueAsset) { + public async deleteBenchmark( + @Param('dataSource') dataSource: DataSource, + @Param('symbol') symbol: string + ) { if ( !hasPermission( this.request.user.permissions, diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index c5b474f0c..ec96666c2 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -257,7 +257,7 @@ export class BenchmarkService { }); if (!assetProfile) { - return; + return null; } let benchmarks = @@ -265,9 +265,9 @@ export class BenchmarkService { PROPERTY_BENCHMARKS )) as BenchmarkProperty[]) ?? []; - benchmarks = benchmarks.filter( - (item) => item.symbolProfileId !== assetProfile.id - ); + benchmarks = benchmarks.filter(({ symbolProfileId }) => { + return symbolProfileId !== assetProfile.id; + }); benchmarks = uniqBy(benchmarks, 'symbolProfileId'); 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 5acba50a5..1f8cf6a66 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 @@ -152,17 +152,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit { }); } - public onUnsetBenchmark({ dataSource, symbol }: UniqueAsset) { - this.dataService - .deleteBenchmark({ dataSource, symbol }) - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - setTimeout(() => { - window.location.reload(); - }, 300); - }); - } - public onSubmit() { let scraperConfiguration = {}; let symbolMapping = {}; @@ -196,6 +185,15 @@ export class AssetProfileDialog implements OnDestroy, OnInit { }); } + public onUnsetBenchmark({ dataSource, symbol }: UniqueAsset) { + this.dataService + .deleteBenchmark({ dataSource, symbol }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + this.isBenchmark = false; + }); + } + public ngOnDestroy() { this.unsubscribeSubject.next(); this.unsubscribeSubject.complete(); diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts index 636f39f8f..1911f5a47 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts @@ -22,8 +22,8 @@ import { AssetProfileDialog } from './asset-profile-dialog.component'; GfPortfolioProportionChartModule, GfValueModule, MatButtonModule, - MatDialogModule, MatCheckboxModule, + MatDialogModule, MatInputModule, MatMenuModule, ReactiveFormsModule, diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 1228f67bf..cf6aad513 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -204,6 +204,10 @@ export class DataService { return this.http.delete(`/api/v1/order/`); } + public deleteBenchmark({ dataSource, symbol }: UniqueAsset) { + return this.http.delete(`/api/v1/benchmark/${dataSource}/${symbol}`); + } + public deleteOrder(aId: string) { return this.http.delete(`/api/v1/order/${aId}`); } @@ -467,10 +471,6 @@ export class DataService { return this.http.post(`/api/v1/benchmark`, benchmark); } - public deleteBenchmark(benchmark: UniqueAsset) { - return this.http.post(`/api/v1/benchmark/remove`, benchmark); - } - public postOrder(aOrder: CreateOrderDto) { return this.http.post(`/api/v1/order`, aOrder); }