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

* Add support for editing countries and sectors

* Update changelog
pull/2889/head
Hugo Persson 10 months ago committed by GitHub
parent 1877b31f00
commit c918deeb1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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/), 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). 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 ## 2.41.0 - 2024-01-16
### Added ### Added

@ -321,10 +321,12 @@ export class AdminService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
dataSource, dataSource,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbol, symbol,
symbolMapping symbolMapping
}: Prisma.SymbolProfileUpdateInput & UniqueAsset) { }: Prisma.SymbolProfileUpdateInput & UniqueAsset) {
@ -332,10 +334,12 @@ export class AdminService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
dataSource, dataSource,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbol, symbol,
symbolMapping symbolMapping
}); });

@ -1,5 +1,11 @@
import { AssetClass, AssetSubClass, Prisma } from '@prisma/client'; 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 { export class UpdateAssetProfileDto {
@IsEnum(AssetClass, { each: true }) @IsEnum(AssetClass, { each: true })
@ -14,6 +20,10 @@ export class UpdateAssetProfileDto {
@IsOptional() @IsOptional()
comment?: string; comment?: string;
@IsArray()
@IsOptional()
countries?: Prisma.InputJsonArray;
@IsString() @IsString()
@IsOptional() @IsOptional()
currency?: string; currency?: string;
@ -26,6 +36,10 @@ export class UpdateAssetProfileDto {
@IsOptional() @IsOptional()
scraperConfiguration?: Prisma.InputJsonObject; scraperConfiguration?: Prisma.InputJsonObject;
@IsArray()
@IsOptional()
sectors?: Prisma.InputJsonArray;
@IsObject() @IsObject()
@IsOptional() @IsOptional()
symbolMapping?: { symbolMapping?: {

@ -89,10 +89,12 @@ export class SymbolProfileService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
dataSource, dataSource,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbol, symbol,
symbolMapping symbolMapping
}: Prisma.SymbolProfileUpdateInput & UniqueAsset) { }: Prisma.SymbolProfileUpdateInput & UniqueAsset) {
@ -101,9 +103,11 @@ export class SymbolProfileService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbolMapping symbolMapping
}, },
where: { dataSource_symbol: { dataSource, symbol } } where: { dataSource_symbol: { dataSource, symbol } }

@ -52,12 +52,14 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: new FormControl<AssetClass>(undefined), assetClass: new FormControl<AssetClass>(undefined),
assetSubClass: new FormControl<AssetSubClass>(undefined), assetSubClass: new FormControl<AssetSubClass>(undefined),
comment: '', comment: '',
countries: '',
currency: '', currency: '',
historicalData: this.formBuilder.group({ historicalData: this.formBuilder.group({
csvString: '' csvString: ''
}), }),
name: ['', Validators.required], name: ['', Validators.required],
scraperConfiguration: '', scraperConfiguration: '',
sectors: '',
symbolMapping: '' symbolMapping: ''
}); });
public assetProfileSubClass: string; public assetProfileSubClass: string;
@ -119,20 +121,20 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.marketDataDetails = marketData; this.marketDataDetails = marketData;
this.sectors = {}; this.sectors = {};
if (assetProfile?.countries?.length > 0) { if (this.assetProfile?.countries?.length > 0) {
for (const country of assetProfile.countries) { for (const { code, name, weight } of this.assetProfile.countries) {
this.countries[country.code] = { this.countries[code] = {
name: country.name, name,
value: country.weight value: weight
}; };
} }
} }
if (assetProfile?.sectors?.length > 0) { if (this.assetProfile?.sectors?.length > 0) {
for (const sector of assetProfile.sectors) { for (const { name, weight } of this.assetProfile.sectors) {
this.sectors[sector.name] = { this.sectors[name] = {
name: sector.name, name,
value: sector.weight value: weight
}; };
} }
} }
@ -141,6 +143,11 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
assetClass: this.assetProfile.assetClass ?? null, assetClass: this.assetProfile.assetClass ?? null,
assetSubClass: this.assetProfile.assetSubClass ?? null, assetSubClass: this.assetProfile.assetSubClass ?? null,
comment: this.assetProfile?.comment ?? '', comment: this.assetProfile?.comment ?? '',
countries: JSON.stringify(
this.assetProfile?.countries.map(({ code, weight }) => {
return { code, weight };
}) ?? []
),
currency: this.assetProfile?.currency, currency: this.assetProfile?.currency,
historicalData: { historicalData: {
csvString: AssetProfileDialog.HISTORICAL_DATA_TEMPLATE csvString: AssetProfileDialog.HISTORICAL_DATA_TEMPLATE
@ -149,6 +156,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
scraperConfiguration: JSON.stringify( scraperConfiguration: JSON.stringify(
this.assetProfile?.scraperConfiguration ?? {} this.assetProfile?.scraperConfiguration ?? {}
), ),
sectors: JSON.stringify(this.assetProfile?.sectors ?? []),
symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {}) symbolMapping: JSON.stringify(this.assetProfile?.symbolMapping ?? {})
}); });
@ -239,15 +247,25 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} }
public onSubmit() { public onSubmit() {
let countries = [];
let scraperConfiguration = {}; let scraperConfiguration = {};
let sectors = [];
let symbolMapping = {}; let symbolMapping = {};
try {
countries = JSON.parse(this.assetProfileForm.controls['countries'].value);
} catch {}
try { try {
scraperConfiguration = JSON.parse( scraperConfiguration = JSON.parse(
this.assetProfileForm.controls['scraperConfiguration'].value this.assetProfileForm.controls['scraperConfiguration'].value
); );
} catch {} } catch {}
try {
sectors = JSON.parse(this.assetProfileForm.controls['sectors'].value);
} catch {}
try { try {
symbolMapping = JSON.parse( symbolMapping = JSON.parse(
this.assetProfileForm.controls['symbolMapping'].value this.assetProfileForm.controls['symbolMapping'].value
@ -255,7 +273,9 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} catch {} } catch {}
const assetProfileData: UpdateAssetProfileDto = { const assetProfileData: UpdateAssetProfileDto = {
countries,
scraperConfiguration, scraperConfiguration,
sectors,
symbolMapping, symbolMapping,
assetClass: this.assetProfileForm.controls['assetClass'].value, assetClass: this.assetProfileForm.controls['assetClass'].value,
assetSubClass: this.assetProfileForm.controls['assetSubClass'].value, assetSubClass: this.assetProfileForm.controls['assetSubClass'].value,

@ -263,6 +263,28 @@
</div> </div>
</mat-form-field> </mat-form-field>
</div> </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> <div>
<mat-form-field appearance="outline" class="w-100"> <mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Note</mat-label> <mat-label i18n>Note</mat-label>

@ -206,10 +206,12 @@ export class AdminService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
dataSource, dataSource,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbol, symbol,
symbolMapping symbolMapping
}: UniqueAsset & UpdateAssetProfileDto) { }: UniqueAsset & UpdateAssetProfileDto) {
@ -219,9 +221,11 @@ export class AdminService {
assetClass, assetClass,
assetSubClass, assetSubClass,
comment, comment,
countries,
currency, currency,
name, name,
scraperConfiguration, scraperConfiguration,
sectors,
symbolMapping symbolMapping
} }
); );

Loading…
Cancel
Save