From 82fe1de1a750380c3cd02066e1682f3f7564eb25 Mon Sep 17 00:00:00 2001 From: Fedron <40535546+Fedron@users.noreply.github.com> Date: Wed, 3 Apr 2024 19:24:38 +0100 Subject: [PATCH] Feature/add support to override asset (sub) class and url in admin control panel (#3218) * Add support to override asset (sub) class and url in admin control panel * Update changelog --- CHANGELOG.md | 3 +++ apps/api/src/app/admin/admin.service.ts | 23 +++++++++++-------- .../src/app/admin/update-asset-profile.dto.ts | 10 +++++++- .../symbol-profile/symbol-profile.service.ts | 6 +++-- .../asset-profile-dialog.component.ts | 9 +++++--- .../asset-profile-dialog.html | 10 ++++++-- apps/client/src/app/services/admin.service.ts | 6 +++-- 7 files changed, 47 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6513785b..f2b8c35b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added the dividend yield to the position detail dialog (experimental) +- Added support to override the asset class of an asset profile in the asset profile details dialog of the admin control +- Added support to override the asset sub class of an asset profile in the asset profile details dialog of the admin control +- Added support to override the url of an asset profile in the asset profile details dialog of the admin control ## 2.70.0 - 2024-04-02 diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index e8a2432e8..2aac43a18 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -25,6 +25,7 @@ import { MarketDataPreset } from '@ghostfolio/common/types'; import { BadRequestException, Injectable } from '@nestjs/common'; import { + AssetClass, AssetSubClass, DataSource, Prisma, @@ -332,12 +333,18 @@ export class AdminService { scraperConfiguration, sectors, symbol, - symbolMapping + symbolMapping, + url }: Prisma.SymbolProfileUpdateInput & UniqueAsset) { + const symbolProfileOverrides = { + assetClass: assetClass as AssetClass, + assetSubClass: assetSubClass as AssetSubClass, + name: name as string, + url: url as string + }; + const updatedSymbolProfile: Prisma.SymbolProfileUpdateInput & UniqueAsset = { - assetClass, - assetSubClass, comment, countries, currency, @@ -347,16 +354,12 @@ export class AdminService { symbol, symbolMapping, ...(dataSource === 'MANUAL' - ? { name } + ? { assetClass, assetSubClass, name, url } : { SymbolProfileOverrides: { upsert: { - create: { - name: name as string - }, - update: { - name: name as string - } + create: symbolProfileOverrides, + update: symbolProfileOverrides } } }) diff --git a/apps/api/src/app/admin/update-asset-profile.dto.ts b/apps/api/src/app/admin/update-asset-profile.dto.ts index 4a0457194..e3de3cab1 100644 --- a/apps/api/src/app/admin/update-asset-profile.dto.ts +++ b/apps/api/src/app/admin/update-asset-profile.dto.ts @@ -5,7 +5,8 @@ import { IsISO4217CurrencyCode, IsObject, IsOptional, - IsString + IsString, + IsUrl } from 'class-validator'; export class UpdateAssetProfileDto { @@ -46,4 +47,11 @@ export class UpdateAssetProfileDto { symbolMapping?: { [dataProvider: string]: string; }; + + @IsOptional() + @IsUrl({ + protocols: ['https'], + require_protocol: true + }) + url?: string; } diff --git a/apps/api/src/services/symbol-profile/symbol-profile.service.ts b/apps/api/src/services/symbol-profile/symbol-profile.service.ts index 656b7b7e4..915b2f716 100644 --- a/apps/api/src/services/symbol-profile/symbol-profile.service.ts +++ b/apps/api/src/services/symbol-profile/symbol-profile.service.ts @@ -98,7 +98,8 @@ export class SymbolProfileService { sectors, symbol, symbolMapping, - SymbolProfileOverrides + SymbolProfileOverrides, + url }: Prisma.SymbolProfileUpdateInput & UniqueAsset) { return this.prismaService.symbolProfile.update({ data: { @@ -111,7 +112,8 @@ export class SymbolProfileService { scraperConfiguration, sectors, symbolMapping, - SymbolProfileOverrides + SymbolProfileOverrides, + url }, where: { dataSource_symbol: { dataSource, symbol } } }); 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 352e709bd..2f0c2546b 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 @@ -64,7 +64,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit { name: ['', Validators.required], scraperConfiguration: '', sectors: '', - symbolMapping: '' + symbolMapping: '', + url: '' }); public assetProfileSubClass: string; public benchmarks: Partial[]; @@ -163,7 +164,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit { this.assetProfile?.scraperConfiguration ?? {} ), sectors: JSON.stringify(this.assetProfile?.sectors ?? []), - symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {}) + symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {}), + url: this.assetProfile?.url ?? '' }); this.assetProfileForm.markAsPristine(); @@ -293,7 +295,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit { currency: (( (this.assetProfileForm.controls['currency'].value) ))?.value, - name: this.assetProfileForm.controls['name'].value + name: this.assetProfileForm.controls['name'].value, + url: this.assetProfileForm.controls['url'].value }; this.adminService 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 93240ba3a..bc6327f0e 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 @@ -224,7 +224,7 @@ /> -
+
Asset Class @@ -237,7 +237,7 @@
-
+
Asset Sub Class @@ -330,6 +330,12 @@
+ + Url + + +
+
Note