Browse Source

refactor: change variable names according to code review

pull/4469/head
tobikugel 4 weeks ago
parent
commit
8346802872
  1. 4
      apps/api/src/app/admin/admin.controller.ts
  2. 70
      apps/api/src/app/admin/admin.service.ts
  3. 10
      apps/api/src/services/market-data/market-data.service.ts
  4. 6
      apps/client/src/app/components/admin-market-data/admin-market-data.component.ts
  5. 75
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts
  6. 29
      apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html

4
apps/api/src/app/admin/admin.controller.ts

@ -334,14 +334,14 @@ export class AdminController {
@Patch('profile-data/:dataSource/:symbol') @Patch('profile-data/:dataSource/:symbol')
@UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async patchAssetProfileData( public async patchAssetProfileData(
@Body() assetProfileData: UpdateAssetProfileDto, @Body() assetProfile: UpdateAssetProfileDto,
@Param('dataSource') dataSource: DataSource, @Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string @Param('symbol') symbol: string
): Promise<EnhancedSymbolProfile> { ): Promise<EnhancedSymbolProfile> {
return this.adminService.patchAssetProfileData( return this.adminService.patchAssetProfileData(
{ dataSource, symbol }, { dataSource, symbol },
{ {
...assetProfileData ...assetProfile
} }
); );
} }

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

@ -520,14 +520,14 @@ export class AdminService {
newDataSource && newDataSource &&
(newSymbol !== symbol || newDataSource !== dataSource) (newSymbol !== symbol || newDataSource !== dataSource)
) { ) {
const [profile] = await this.symbolProfileService.getSymbolProfiles([ const [assetProfile] = await this.symbolProfileService.getSymbolProfiles([
{ {
dataSource: newDataSource as DataSource, dataSource: newDataSource as DataSource,
symbol: newSymbol as string symbol: newSymbol as string
} }
]); ]);
if (profile) { if (assetProfile) {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.CONFLICT), getReasonPhrase(StatusCodes.CONFLICT),
StatusCodes.CONFLICT StatusCodes.CONFLICT
@ -535,37 +535,35 @@ export class AdminService {
} }
try { try {
await this.symbolProfileService.updateAssetProfileIdentifier( Promise.all([
{ await this.symbolProfileService.updateAssetProfileIdentifier(
dataSource, {
symbol dataSource,
}, symbol
{ },
dataSource: newDataSource as DataSource, {
symbol: newSymbol as string dataSource: newDataSource as DataSource,
} symbol: newSymbol as string
); }
),
await this.marketDataService.updateAssetProfileIdentifier( await this.marketDataService.updateAssetProfileIdentifier(
{ {
dataSource, dataSource,
symbol symbol
}, },
{
dataSource: newDataSource as DataSource,
symbol: newSymbol as string
}
);
const [symbolProfile] =
await this.symbolProfileService.getSymbolProfiles([
{ {
dataSource: newDataSource as DataSource, dataSource: newDataSource as DataSource,
symbol: newSymbol as string symbol: newSymbol as string
} }
]); )
]);
return symbolProfile; return this.symbolProfileService.getSymbolProfiles([
{
dataSource: newDataSource as DataSource,
symbol: newSymbol as string
}
])?.[0];
} catch { } catch {
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.BAD_REQUEST), getReasonPhrase(StatusCodes.BAD_REQUEST),
@ -610,16 +608,12 @@ export class AdminService {
updatedSymbolProfile updatedSymbolProfile
); );
const [symbolProfile] = await this.symbolProfileService.getSymbolProfiles( return this.symbolProfileService.getSymbolProfiles([
[ {
{ dataSource: dataSource as DataSource,
dataSource: dataSource as DataSource, symbol: symbol as string
symbol: symbol as string }
} ])?.[0];
]
);
return symbolProfile;
} }
} }

10
apps/api/src/services/market-data/market-data.service.ts

@ -120,14 +120,8 @@ export class MarketDataService {
symbol: newAssetProfileIdentifier.symbol symbol: newAssetProfileIdentifier.symbol
}, },
where: { where: {
AND: [ dataSource: oldAssetProfileIdentifier.dataSource,
{ symbol: oldAssetProfileIdentifier.symbol
dataSource: oldAssetProfileIdentifier.dataSource
},
{
symbol: oldAssetProfileIdentifier.symbol
}
]
} }
}); });
} }

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

@ -390,9 +390,9 @@ export class AdminMarketDataComponent
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe( .subscribe(
(newAssetProfileIdentifer: AssetProfileIdentifier | undefined) => { (newAssetProfileIdentifier: AssetProfileIdentifier | undefined) => {
if (newAssetProfileIdentifer) { if (newAssetProfileIdentifier) {
this.onOpenAssetProfileDialog(newAssetProfileIdentifer); this.onOpenAssetProfileDialog(newAssetProfileIdentifier);
} else { } else {
this.router.navigate(['.'], { relativeTo: this.route }); this.router.navigate(['.'], { relativeTo: this.route });
} }

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

@ -43,6 +43,7 @@ import {
SymbolProfile SymbolProfile
} from '@prisma/client'; } from '@prisma/client';
import { format } from 'date-fns'; import { format } from 'date-fns';
import { StatusCodes } from 'http-status-codes';
import ms from 'ms'; import ms from 'ms';
import { EMPTY, Subject } from 'rxjs'; import { EMPTY, Subject } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators'; import { catchError, takeUntil } from 'rxjs/operators';
@ -93,7 +94,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
}); });
public assetProfileIdentifierForm = this.formBuilder.group( public assetProfileIdentifierForm = this.formBuilder.group(
{ {
symbol: new FormControl<AssetProfileIdentifier>( assetProfileIdentifier: new FormControl<AssetProfileIdentifier>(
{ symbol: null, dataSource: null }, { symbol: null, dataSource: null },
[Validators.required] [Validators.required]
) )
@ -111,7 +112,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
public ghostfolioScraperApiSymbolPrefix = ghostfolioScraperApiSymbolPrefix; public ghostfolioScraperApiSymbolPrefix = ghostfolioScraperApiSymbolPrefix;
public historicalDataItems: LineChartItem[]; public historicalDataItems: LineChartItem[];
public isBenchmark = false; public isBenchmark = false;
public isEditSymbolMode = false; public isEditAssetProfileIdentifierMode = false;
public marketDataItems: MarketData[] = []; public marketDataItems: MarketData[] = [];
public modeValues = [ public modeValues = [
{ {
@ -250,30 +251,16 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
}); });
} }
private isNewSymbolValid(control: AbstractControl): ValidationErrors { public get isAssetProfileIdentifierEditable() {
const currentAssetProfileIdentifier: AssetProfileIdentifier | undefined =
control.get('symbol').value;
if (
currentAssetProfileIdentifier?.dataSource === this.data?.dataSource &&
currentAssetProfileIdentifier?.symbol === this.data?.symbol
) {
return {
equalsPreviousSymbol: true
};
}
}
public get isSymbolEditable() {
return !this.assetProfileForm.dirty; return !this.assetProfileForm.dirty;
} }
public get isSymbolEditButtonInvisible() { public get isAssetProfileIdentifierEditButtonVisible() {
return this.assetProfile?.dataSource === 'MANUAL'; return this.assetProfile?.dataSource !== 'MANUAL';
} }
public onCancelEditSymboleMode() { public onCancelEditAssetProfileIdentifierMode() {
this.isEditSymbolMode = false; this.isEditAssetProfileIdentifierMode = false;
this.assetProfileForm.enable(); this.assetProfileForm.enable();
@ -328,8 +315,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
}); });
} }
public onSetEditSymboleMode() { public onSetEditAssetProfileIdentifierMode() {
this.isEditSymbolMode = true; this.isEditAssetProfileIdentifierMode = true;
this.assetProfileForm.disable(); this.assetProfileForm.disable();
@ -337,17 +324,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
} }
public async onSubmitAssetProfileIdentifierForm() { public async onSubmitAssetProfileIdentifierForm() {
const assetProfileIdentifierData: UpdateAssetProfileDto = { const assetProfileIdentifier: UpdateAssetProfileDto = {
dataSource: dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
this.assetProfileIdentifierForm.get('symbol').value.dataSource, .value.dataSource,
symbol: this.assetProfileIdentifierForm.get('symbol').value.symbol symbol: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.symbol
}; };
try { try {
await validateObjectForForm({ await validateObjectForForm({
classDto: UpdateAssetProfileDto, classDto: UpdateAssetProfileDto,
form: this.assetProfileIdentifierForm, form: this.assetProfileIdentifierForm,
object: assetProfileIdentifierData object: assetProfileIdentifier
}); });
} catch (error) { } catch (error) {
console.error(error); console.error(error);
@ -362,14 +350,14 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
symbol: this.data.symbol symbol: this.data.symbol
}, },
{ {
...assetProfileIdentifierData ...assetProfileIdentifier
} }
) )
.pipe( .pipe(
catchError((error: HttpErrorResponse) => { catchError((error: HttpErrorResponse) => {
if (error.status === 409) { if (error.status === StatusCodes.CONFLICT) {
this.snackBar.open( this.snackBar.open(
$localize`This symbol is already in use.`, $localize`${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}) is already in use.`,
undefined, undefined,
{ {
duration: ms('3 seconds') duration: ms('3 seconds')
@ -377,7 +365,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
); );
} else { } else {
this.snackBar.open( this.snackBar.open(
$localize`An error occurred while updating the symbol.`, $localize`An error occurred while updating to ${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}).`,
undefined, undefined,
{ {
duration: ms('3 seconds') duration: ms('3 seconds')
@ -390,12 +378,12 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
takeUntil(this.unsubscribeSubject) takeUntil(this.unsubscribeSubject)
) )
.subscribe(() => { .subscribe(() => {
const newAssetProfileIdentifer = { const newAssetProfileIdentifier = {
dataSource: assetProfileIdentifierData.dataSource, dataSource: assetProfileIdentifier.dataSource,
symbol: assetProfileIdentifierData.symbol symbol: assetProfileIdentifier.symbol
}; };
this.dialogRef.close(newAssetProfileIdentifer); this.dialogRef.close(newAssetProfileIdentifier);
}); });
} }
@ -554,7 +542,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
public ngOnDestroy() { public ngOnDestroy() {
this.unsubscribeSubject.next(); this.unsubscribeSubject.next();
this.unsubscribeSubject.complete(); this.unsubscribeSubject.complete();
} }
@ -563,4 +550,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
this.assetProfileFormElement.nativeElement.requestSubmit(); this.assetProfileFormElement.nativeElement.requestSubmit();
} }
} }
private isNewSymbolValid(control: AbstractControl): ValidationErrors {
const currentAssetProfileIdentifier: AssetProfileIdentifier | undefined =
control.get('assetProfileIdentifier').value;
if (
currentAssetProfileIdentifier?.dataSource === this.data?.dataSource &&
currentAssetProfileIdentifier?.symbol === this.data?.symbol
) {
return {
equalsPreviousProfileIdentifier: true
};
}
}
} }

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

@ -86,7 +86,7 @@
/> />
<div class="row"> <div class="row">
@if (isEditSymbolMode) { @if (isEditAssetProfileIdentifierMode) {
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<form <form
class="align-items-center d-flex" class="align-items-center d-flex"
@ -100,7 +100,7 @@
<mat-form-field appearance="outline" class="gf-spacer without-hint"> <mat-form-field appearance="outline" class="gf-spacer without-hint">
<mat-label i18n>Name, symbol or ISIN</mat-label> <mat-label i18n>Name, symbol or ISIN</mat-label>
<gf-symbol-autocomplete <gf-symbol-autocomplete
formControlName="symbol" formControlName="assetProfileIdentifier"
[includeIndices]="true" [includeIndices]="true"
/> />
</mat-form-field> </mat-form-field>
@ -110,19 +110,24 @@
mat-flat-button mat-flat-button
type="submit" type="submit"
[disabled]=" [disabled]="
assetProfileIdentifierForm.hasError('invalidData', 'symbol') || assetProfileIdentifierForm.hasError(
assetProfileIdentifierForm.hasError('equalsPreviousSymbol') 'invalidData',
'assetProfileIdentifier'
) ||
assetProfileIdentifierForm.hasError(
'equalsPreviousProfileIdentifier'
)
" "
> >
Apply <ng-container i18n>Apply</ng-container>
</button> </button>
<button <button
class="mx-1 no-min-width px-2" class="mx-1 no-min-width px-2"
mat-button mat-button
type="button" type="button"
(click)="onCancelEditSymboleMode()" (click)="onCancelEditAssetProfileIdentifierMode()"
> >
Cancel <ng-container i18n>Cancel</ng-container>
</button> </button>
</form> </form>
</div> </div>
@ -132,7 +137,7 @@
>Symbol</gf-value >Symbol</gf-value
> >
</div> </div>
<div class="col-6 mb-3 d-flex justify-content-between"> <div class="col-6 d-flex justify-content-between mb-3">
<gf-value <gf-value
class="col-11" class="col-11"
i18n i18n
@ -146,11 +151,11 @@
class="col-1 mx-1 no-min-width px-2" class="col-1 mx-1 no-min-width px-2"
mat-button mat-button
type="button" type="button"
[disabled]="!isSymbolEditable" [disabled]="!isAssetProfileIdentifierEditable"
[ngClass]="{ [ngClass]="{
'd-none': isSymbolEditButtonInvisible 'd-none': !isAssetProfileIdentifierEditButtonVisible
}" }"
(click)="onSetEditSymboleMode()" (click)="onSetEditAssetProfileIdentifierMode()"
> >
<ion-icon name="create-outline"></ion-icon> <ion-icon name="create-outline"></ion-icon>
</button> </button>
@ -307,7 +312,7 @@
color="primary" color="primary"
i18n i18n
[checked]="isBenchmark" [checked]="isBenchmark"
[disabled]="isEditSymbolMode" [disabled]="isEditAssetProfileIdentifierMode"
(change)=" (change)="
isBenchmark isBenchmark
? onUnsetBenchmark({ ? onUnsetBenchmark({

Loading…
Cancel
Save