Browse Source

Refactoring

pull/2075/head
Thomas 2 years ago
parent
commit
47b9ed8ee5
  1. 6
      apps/api/src/app/admin/admin.service.ts
  2. 9
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  3. 2
      apps/client/src/app/components/admin-market-data/admin-market-data.scss
  4. 23
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts
  5. 6
      apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html

6
apps/api/src/app/admin/admin.service.ts

@ -42,18 +42,18 @@ export class AdminService {
symbol
}: UniqueAsset): Promise<SymbolProfile | never> {
try {
const assetProfile = await this.dataProviderService.getAssetProfiles([
const assetProfiles = await this.dataProviderService.getAssetProfiles([
{ dataSource, symbol }
]);
if (!assetProfile[symbol].currency) {
if (!assetProfiles[symbol]?.currency) {
throw new BadRequestException(
`Asset profile not found for ${symbol} (${dataSource})`
);
}
return await this.symbolProfileService.add(
assetProfile[symbol] as Prisma.SymbolProfileCreateInput
assetProfiles[symbol] as Prisma.SymbolProfileCreateInput
);
} catch (error) {
if (

9
apps/client/src/app/components/admin-market-data/admin-market-data.component.ts

@ -252,6 +252,7 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((user) => {
this.user = user;
const dialogRef = this.dialog.open(CreateAssetProfileDialog, {
autoFocus: false,
data: <CreateAssetProfileDialogParams>{
@ -264,15 +265,11 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
dialogRef
.afterClosed()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((data: any) => {
const dataSource = data?.dataSource;
const symbol = data?.symbol;
.subscribe(({ dataSource, symbol }) => {
if (dataSource && symbol) {
this.adminService
.addAssetProfile({ dataSource, symbol })
.pipe(
takeUntil(this.unsubscribeSubject),
switchMap(() => {
this.isLoading = true;
this.changeDetectorRef.markForCheck();
@ -286,8 +283,8 @@ export class AdminMarketDataComponent implements OnDestroy, OnInit {
.subscribe(({ marketData }) => {
this.dataSource = new MatTableDataSource(marketData);
this.dataSource.sort = this.sort;
this.isLoading = false;
this.changeDetectorRef.markForCheck();
});
}

2
apps/client/src/app/components/admin-market-data/admin-market-data.scss

@ -4,9 +4,9 @@
display: block;
.fab-container {
bottom: 2rem;
position: fixed;
right: 2rem;
bottom: 2rem;
z-index: 999;
}
}

23
apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.component.ts

@ -7,24 +7,19 @@ import {
OnInit
} from '@angular/core';
import {
AbstractControl,
FormBuilder,
FormControl,
FormGroup,
ValidationErrors,
ValidatorFn,
Validators
} from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { CreateAssetProfileDialogParams } from '@ghostfolio/client/components/admin-market-data/create-asset-profile-dialog/interfaces/interfaces';
import { MatDialogRef } from '@angular/material/dialog';
import { AdminService } from '@ghostfolio/client/services/admin.service';
import { AdminMarketDataItem } from '@ghostfolio/common/interfaces';
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'h-100' },
selector: 'gf-create-asset-profile-dialog',
templateUrl: 'create-asset-profile-dialog.html',
changeDetection: ChangeDetectionStrategy.OnPush
templateUrl: 'create-asset-profile-dialog.html'
})
export class CreateAssetProfileDialog implements OnInit, OnDestroy {
public createAssetProfileForm: FormGroup;
@ -36,15 +31,17 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
public readonly formBuilder: FormBuilder
) {}
ngOnInit() {
public ngOnInit() {
this.createAssetProfileForm = this.formBuilder.group({
searchSymbol: new FormControl(null, [Validators.required])
});
}
ngOnDestroy(): void {}
public onCancel() {
this.dialogRef.close();
}
onSubmit() {
public onSubmit() {
this.dialogRef.close({
dataSource:
this.createAssetProfileForm.controls['searchSymbol'].value.dataSource,
@ -52,7 +49,5 @@ export class CreateAssetProfileDialog implements OnInit, OnDestroy {
});
}
onCancel() {
this.dialogRef.close();
}
public ngOnDestroy() {}
}

6
apps/client/src/app/components/admin-market-data/create-asset-profile-dialog/create-asset-profile-dialog.html

@ -9,12 +9,6 @@
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Name, symbol or ISIN</mat-label>
<gf-symbol-autocomplete formControlName="searchSymbol" />
<mat-error
*ngIf="createAssetProfileForm.controls['searchSymbol'].hasError('isSymbolExists')"
i18n
>
Asset profile already present
</mat-error>
</mat-form-field>
</div>
<div class="d-flex justify-content-end" mat-dialog-actions>

Loading…
Cancel
Save