Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Feature/Support for editing countries and sectors (#2854)

Hugo Perssonc918deeb1c08
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f50dc0d007..714d45de77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Added
+
+- Added support to edit countries in the asset profile details dialog of the admin control
+- Added support to edit sectors in the asset profile details dialog of the admin control
+
## 2.41.0 - 2024-01-16
### Added
diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts
index 51b93517f6..b77d773550 100644
--- a/apps/api/src/app/admin/admin.service.ts
+++ b/apps/api/src/app/admin/admin.service.ts
@@ -321,10 +321,12 @@ export class AdminService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
dataSource,
name,
scraperConfiguration,
+ sectors,
symbol,
symbolMapping
}: Prisma.SymbolProfileUpdateInput & UniqueAsset) {
@@ -332,10 +334,12 @@ export class AdminService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
dataSource,
name,
scraperConfiguration,
+ sectors,
symbol,
symbolMapping
});
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 56794606c0..624acff9f2 100644
--- a/apps/api/src/app/admin/update-asset-profile.dto.ts
+++ b/apps/api/src/app/admin/update-asset-profile.dto.ts
@@ -1,5 +1,11 @@
import { AssetClass, AssetSubClass, Prisma } from '@prisma/client';
-import { IsEnum, IsObject, IsOptional, IsString } from 'class-validator';
+import {
+ IsArray,
+ IsEnum,
+ IsObject,
+ IsOptional,
+ IsString
+} from 'class-validator';
export class UpdateAssetProfileDto {
@IsEnum(AssetClass, { each: true })
@@ -14,6 +20,10 @@ export class UpdateAssetProfileDto {
@IsOptional()
comment?: string;
+ @IsArray()
+ @IsOptional()
+ countries?: Prisma.InputJsonArray;
+
@IsString()
@IsOptional()
currency?: string;
@@ -26,6 +36,10 @@ export class UpdateAssetProfileDto {
@IsOptional()
scraperConfiguration?: Prisma.InputJsonObject;
+ @IsArray()
+ @IsOptional()
+ sectors?: Prisma.InputJsonArray;
+
@IsObject()
@IsOptional()
symbolMapping?: {
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 5f808b3db9..1cab9b061c 100644
--- a/apps/api/src/services/symbol-profile/symbol-profile.service.ts
+++ b/apps/api/src/services/symbol-profile/symbol-profile.service.ts
@@ -89,10 +89,12 @@ export class SymbolProfileService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
dataSource,
name,
scraperConfiguration,
+ sectors,
symbol,
symbolMapping
}: Prisma.SymbolProfileUpdateInput & UniqueAsset) {
@@ -101,9 +103,11 @@ export class SymbolProfileService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
name,
scraperConfiguration,
+ sectors,
symbolMapping
},
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 6a6e4e64ad..f949d9e410 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
@@ -52,12 +52,14 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: new FormControl<AssetClass>(undefined),
assetSubClass: new FormControl<AssetSubClass>(undefined),
comment: '',
+ countries: '',
currency: '',
historicalData: this.formBuilder.group({
csvString: ''
}),
name: ['', Validators.required],
scraperConfiguration: '',
+ sectors: '',
symbolMapping: ''
});
public assetProfileSubClass: string;
@@ -119,20 +121,20 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.marketDataDetails = marketData;
this.sectors = {};
- if (assetProfile?.countries?.length > 0) {
- for (const country of assetProfile.countries) {
- this.countries[country.code] = {
- name: country.name,
- value: country.weight
+ if (this.assetProfile?.countries?.length > 0) {
+ for (const { code, name, weight } of this.assetProfile.countries) {
+ this.countries[code] = {
+ name,
+ value: weight
};
}
}
- if (assetProfile?.sectors?.length > 0) {
- for (const sector of assetProfile.sectors) {
- this.sectors[sector.name] = {
- name: sector.name,
- value: sector.weight
+ if (this.assetProfile?.sectors?.length > 0) {
+ for (const { name, weight } of this.assetProfile.sectors) {
+ this.sectors[name] = {
+ name,
+ value: weight
};
}
}
@@ -141,6 +143,11 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: this.assetProfile.assetClass ?? null,
assetSubClass: this.assetProfile.assetSubClass ?? null,
comment: this.assetProfile?.comment ?? '',
+ countries: JSON.stringify(
+ this.assetProfile?.countries.map(({ code, weight }) => {
+ return { code, weight };
+ }) ?? []
+ ),
currency: this.assetProfile?.currency,
historicalData: {
csvString: AssetProfileDialog.HISTORICAL_DATA_TEMPLATE
@@ -149,6 +156,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
scraperConfiguration: JSON.stringify(
this.assetProfile?.scraperConfiguration ?? {}
),
+ sectors: JSON.stringify(this.assetProfile?.sectors ?? []),
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {})
});
@@ -239,15 +247,25 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
}
public onSubmit() {
+ let countries = [];
let scraperConfiguration = {};
+ let sectors = [];
let symbolMapping = {};
+ try {
+ countries = JSON.parse(this.assetProfileForm.controls['countries'].value);
+ } catch {}
+
try {
scraperConfiguration = JSON.parse(
this.assetProfileForm.controls['scraperConfiguration'].value
);
} catch {}
+ try {
+ sectors = JSON.parse(this.assetProfileForm.controls['sectors'].value);
+ } catch {}
+
try {
symbolMapping = JSON.parse(
this.assetProfileForm.controls['symbolMapping'].value
@@ -255,7 +273,9 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} catch {}
const assetProfileData: UpdateAssetProfileDto = {
+ countries,
scraperConfiguration,
+ sectors,
symbolMapping,
assetClass: this.assetProfileForm.controls['assetClass'].value,
assetSubClass: this.assetProfileForm.controls['assetSubClass'].value,
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 d784c5dc1e..0f5b5b7f24 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
@@ -263,6 +263,28 @@
</div>
</mat-form-field>
</div>
+ <div *ngIf="assetProfile?.dataSource === 'MANUAL'">
+ <mat-form-field appearance="outline" class="w-100">
+ <mat-label i18n>Sectors</mat-label>
+ <textarea
+ cdkTextareaAutosize
+ formControlName="sectors"
+ matInput
+ type="text"
+ ></textarea>
+ </mat-form-field>
+ </div>
+ <div *ngIf="assetProfile?.dataSource === 'MANUAL'">
+ <mat-form-field appearance="outline" class="w-100">
+ <mat-label i18n>Countries</mat-label>
+ <textarea
+ cdkTextareaAutosize
+ formControlName="countries"
+ matInput
+ type="text"
+ ></textarea>
+ </mat-form-field>
+ </div>
<div>
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Note</mat-label>
diff --git a/apps/client/src/app/services/admin.service.ts b/apps/client/src/app/services/admin.service.ts
index a1c7d626a1..d8060e240b 100644
--- a/apps/client/src/app/services/admin.service.ts
+++ b/apps/client/src/app/services/admin.service.ts
@@ -206,10 +206,12 @@ export class AdminService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
dataSource,
name,
scraperConfiguration,
+ sectors,
symbol,
symbolMapping
}: UniqueAsset & UpdateAssetProfileDto) {
@@ -219,9 +221,11 @@ export class AdminService {
assetClass,
assetSubClass,
comment,
+ countries,
currency,
name,
scraperConfiguration,
+ sectors,
symbolMapping
}
);