diff --git a/apps/api/src/app/account/create-account.dto.ts b/apps/api/src/app/account/create-account.dto.ts index eb24d959a..fff982ecf 100644 --- a/apps/api/src/app/account/create-account.dto.ts +++ b/apps/api/src/app/account/create-account.dto.ts @@ -12,7 +12,7 @@ import { isString } from 'lodash'; export class CreateAccountDto { @IsOptional() @IsString() - accountType: AccountType; + accountType?: AccountType; @IsNumber() balance: number; diff --git a/apps/api/src/app/account/update-account.dto.ts b/apps/api/src/app/account/update-account.dto.ts index a91914482..7ab829454 100644 --- a/apps/api/src/app/account/update-account.dto.ts +++ b/apps/api/src/app/account/update-account.dto.ts @@ -12,7 +12,7 @@ import { isString } from 'lodash'; export class UpdateAccountDto { @IsOptional() @IsString() - accountType: AccountType; + accountType?: AccountType; @IsNumber() balance: number; diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts index f0178f2f5..07529440d 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.component.ts @@ -4,7 +4,10 @@ import { Inject, OnDestroy } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto'; +import { UpdateAccountDto } from '@ghostfolio/api/app/account/update-account.dto'; import { DataService } from '@ghostfolio/client/services/data.service'; import { Subject } from 'rxjs'; @@ -18,6 +21,7 @@ import { CreateOrUpdateAccountDialogParams } from './interfaces/interfaces'; templateUrl: 'create-or-update-account-dialog.html' }) export class CreateOrUpdateAccountDialog implements OnDestroy { + public accountForm: FormGroup; public currencies: string[] = []; public platforms: { id: string; name: string }[]; @@ -26,7 +30,8 @@ export class CreateOrUpdateAccountDialog implements OnDestroy { public constructor( private dataService: DataService, public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccountDialogParams + @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateAccountDialogParams, + private formBuilder: FormBuilder ) {} ngOnInit() { @@ -34,6 +39,36 @@ export class CreateOrUpdateAccountDialog implements OnDestroy { this.currencies = currencies; this.platforms = platforms; + + this.accountForm = this.formBuilder.group({ + accountId: [this.data.account.id], + balance: [this.data.account.balance, Validators.required], + comment: [this.data.account.comment], + currency: [this.data.account.currency, Validators.required], + isExcluded: [this.data.account.isExcluded], + platformId: [this.data.account.platformId], + name: [this.data.account.name, Validators.required] + }); + } + + public onSubmit() { + const account: CreateAccountDto | UpdateAccountDto = { + balance: this.accountForm.controls['balance'].value, + comment: this.accountForm.controls['comment'].value, + currency: this.accountForm.controls['currency'].value, + id: this.accountForm.controls['accountId'].value, + isExcluded: this.accountForm.controls['isExcluded'].value, + name: this.accountForm.controls['name'].value, + platformId: this.accountForm.controls['platformId'].value + }; + + if (this.data.account.id) { + (account as UpdateAccountDto).id = this.data.account.id; + } else { + delete (account as CreateAccountDto).id; + } + + this.dialogRef.close({ account }); } public onCancel() { diff --git a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html index 7b6f399a0..53fbe8419 100644 --- a/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html +++ b/apps/client/src/app/pages/accounts/create-or-update-account-dialog/create-or-update-account-dialog.html @@ -1,17 +1,22 @@ -
+

Update account

Add account

Name - +
Currency - + {{ currency }} @@ -22,11 +27,10 @@ Cash Balance {{ data.account.currency }} @@ -34,7 +38,7 @@
Platform - + {{ platform.name }} @@ -58,8 +61,7 @@
Exclude from Analysis
@@ -68,9 +70,8 @@ Account ID
@@ -80,8 +81,8 @@