Browse Source

refactor: change variable names according to code review

pull/4469/head
tobikugel 3 weeks ago
committed by Thomas Kaul
parent
commit
13f7570a44
  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')
@UseGuards(AuthGuard('jwt'), HasPermissionGuard)
public async patchAssetProfileData(
@Body() assetProfileData: UpdateAssetProfileDto,
@Body() assetProfile: UpdateAssetProfileDto,
@Param('dataSource') dataSource: DataSource,
@Param('symbol') symbol: string
): Promise<EnhancedSymbolProfile> {
return this.adminService.patchAssetProfileData(
{ dataSource, symbol },
{
...assetProfileData
...assetProfile
}
);
}

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

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

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

@ -120,14 +120,8 @@ export class MarketDataService {
symbol: newAssetProfileIdentifier.symbol
},
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()
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe(
(newAssetProfileIdentifer: AssetProfileIdentifier | undefined) => {
if (newAssetProfileIdentifer) {
this.onOpenAssetProfileDialog(newAssetProfileIdentifer);
(newAssetProfileIdentifier: AssetProfileIdentifier | undefined) => {
if (newAssetProfileIdentifier) {
this.onOpenAssetProfileDialog(newAssetProfileIdentifier);
} else {
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
} from '@prisma/client';
import { format } from 'date-fns';
import { StatusCodes } from 'http-status-codes';
import ms from 'ms';
import { EMPTY, Subject } from 'rxjs';
import { catchError, takeUntil } from 'rxjs/operators';
@ -93,7 +94,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
});
public assetProfileIdentifierForm = this.formBuilder.group(
{
symbol: new FormControl<AssetProfileIdentifier>(
assetProfileIdentifier: new FormControl<AssetProfileIdentifier>(
{ symbol: null, dataSource: null },
[Validators.required]
)
@ -111,7 +112,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
public ghostfolioScraperApiSymbolPrefix = ghostfolioScraperApiSymbolPrefix;
public historicalDataItems: LineChartItem[];
public isBenchmark = false;
public isEditSymbolMode = false;
public isEditAssetProfileIdentifierMode = false;
public marketDataItems: MarketData[] = [];
public modeValues = [
{
@ -250,30 +251,16 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
});
}
private isNewSymbolValid(control: AbstractControl): ValidationErrors {
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() {
public get isAssetProfileIdentifierEditable() {
return !this.assetProfileForm.dirty;
}
public get isSymbolEditButtonInvisible() {
return this.assetProfile?.dataSource === 'MANUAL';
public get isAssetProfileIdentifierEditButtonVisible() {
return this.assetProfile?.dataSource !== 'MANUAL';
}
public onCancelEditSymboleMode() {
this.isEditSymbolMode = false;
public onCancelEditAssetProfileIdentifierMode() {
this.isEditAssetProfileIdentifierMode = false;
this.assetProfileForm.enable();
@ -328,8 +315,8 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
});
}
public onSetEditSymboleMode() {
this.isEditSymbolMode = true;
public onSetEditAssetProfileIdentifierMode() {
this.isEditAssetProfileIdentifierMode = true;
this.assetProfileForm.disable();
@ -337,17 +324,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
}
public async onSubmitAssetProfileIdentifierForm() {
const assetProfileIdentifierData: UpdateAssetProfileDto = {
dataSource:
this.assetProfileIdentifierForm.get('symbol').value.dataSource,
symbol: this.assetProfileIdentifierForm.get('symbol').value.symbol
const assetProfileIdentifier: UpdateAssetProfileDto = {
dataSource: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.dataSource,
symbol: this.assetProfileIdentifierForm.get('assetProfileIdentifier')
.value.symbol
};
try {
await validateObjectForForm({
classDto: UpdateAssetProfileDto,
form: this.assetProfileIdentifierForm,
object: assetProfileIdentifierData
object: assetProfileIdentifier
});
} catch (error) {
console.error(error);
@ -362,14 +350,14 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
symbol: this.data.symbol
},
{
...assetProfileIdentifierData
...assetProfileIdentifier
}
)
.pipe(
catchError((error: HttpErrorResponse) => {
if (error.status === 409) {
if (error.status === StatusCodes.CONFLICT) {
this.snackBar.open(
$localize`This symbol is already in use.`,
$localize`${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}) is already in use.`,
undefined,
{
duration: ms('3 seconds')
@ -377,7 +365,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
);
} else {
this.snackBar.open(
$localize`An error occurred while updating the symbol.`,
$localize`An error occurred while updating to ${assetProfileIdentifier.symbol} (${assetProfileIdentifier.dataSource}).`,
undefined,
{
duration: ms('3 seconds')
@ -390,12 +378,12 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
takeUntil(this.unsubscribeSubject)
)
.subscribe(() => {
const newAssetProfileIdentifer = {
dataSource: assetProfileIdentifierData.dataSource,
symbol: assetProfileIdentifierData.symbol
const newAssetProfileIdentifier = {
dataSource: assetProfileIdentifier.dataSource,
symbol: assetProfileIdentifier.symbol
};
this.dialogRef.close(newAssetProfileIdentifer);
this.dialogRef.close(newAssetProfileIdentifier);
});
}
@ -554,7 +542,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
@ -563,4 +550,18 @@ export class AssetProfileDialog implements OnDestroy, OnInit {
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">
@if (isEditSymbolMode) {
@if (isEditAssetProfileIdentifierMode) {
<div class="col-12 mb-4">
<form
class="align-items-center d-flex"
@ -100,7 +100,7 @@
<mat-form-field appearance="outline" class="gf-spacer without-hint">
<mat-label i18n>Name, symbol or ISIN</mat-label>
<gf-symbol-autocomplete
formControlName="symbol"
formControlName="assetProfileIdentifier"
[includeIndices]="true"
/>
</mat-form-field>
@ -110,19 +110,24 @@
mat-flat-button
type="submit"
[disabled]="
assetProfileIdentifierForm.hasError('invalidData', 'symbol') ||
assetProfileIdentifierForm.hasError('equalsPreviousSymbol')
assetProfileIdentifierForm.hasError(
'invalidData',
'assetProfileIdentifier'
) ||
assetProfileIdentifierForm.hasError(
'equalsPreviousProfileIdentifier'
)
"
>
Apply
<ng-container i18n>Apply</ng-container>
</button>
<button
class="mx-1 no-min-width px-2"
mat-button
type="button"
(click)="onCancelEditSymboleMode()"
(click)="onCancelEditAssetProfileIdentifierMode()"
>
Cancel
<ng-container i18n>Cancel</ng-container>
</button>
</form>
</div>
@ -132,7 +137,7 @@
>Symbol</gf-value
>
</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
class="col-11"
i18n
@ -146,11 +151,11 @@
class="col-1 mx-1 no-min-width px-2"
mat-button
type="button"
[disabled]="!isSymbolEditable"
[disabled]="!isAssetProfileIdentifierEditable"
[ngClass]="{
'd-none': isSymbolEditButtonInvisible
'd-none': !isAssetProfileIdentifierEditButtonVisible
}"
(click)="onSetEditSymboleMode()"
(click)="onSetEditAssetProfileIdentifierMode()"
>
<ion-icon name="create-outline"></ion-icon>
</button>
@ -307,7 +312,7 @@
color="primary"
i18n
[checked]="isBenchmark"
[disabled]="isEditSymbolMode"
[disabled]="isEditAssetProfileIdentifierMode"
(change)="
isBenchmark
? onUnsetBenchmark({

Loading…
Cancel
Save