Feature/validate account balance creation/update using DTO (#3400)

* Validate create account balance using DTO
pull/3405/head
Fedron 6 months ago committed by GitHub
parent 9ad1c2177c
commit 5616bc4956
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +1,4 @@
import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/create-account-balance.dto';
import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface';
import { DataService } from '@ghostfolio/client/services/data.service'; import { DataService } from '@ghostfolio/client/services/data.service';
import { UserService } from '@ghostfolio/client/services/user/user.service'; import { UserService } from '@ghostfolio/client/services/user/user.service';
@ -95,19 +96,9 @@ export class AccountDetailDialog implements OnDestroy, OnInit {
this.dialogRef.close(); this.dialogRef.close();
} }
public onAddAccountBalance({ public onAddAccountBalance(accountBalance: CreateAccountBalanceDto) {
balance,
date
}: {
balance: number;
date: Date;
}) {
this.dataService this.dataService
.postAccountBalance({ .postAccountBalance(accountBalance)
balance,
date,
accountId: this.data.accountId
})
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntil(this.unsubscribeSubject))
.subscribe(() => { .subscribe(() => {
this.fetchAccount(); this.fetchAccount();

@ -1,4 +1,5 @@
import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto'; import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto';
import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/create-account-balance.dto';
import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto'; import { CreateAccountDto } from '@ghostfolio/api/app/account/create-account.dto';
import { TransferBalanceDto } from '@ghostfolio/api/app/account/transfer-balance.dto'; import { TransferBalanceDto } from '@ghostfolio/api/app/account/transfer-balance.dto';
import { UpdateAccountDto } from '@ghostfolio/api/app/account/update-account.dto'; import { UpdateAccountDto } from '@ghostfolio/api/app/account/update-account.dto';
@ -601,20 +602,11 @@ export class DataService {
return this.http.post<OrderModel>(`/api/v1/account`, aAccount); return this.http.post<OrderModel>(`/api/v1/account`, aAccount);
} }
public postAccountBalance({ public postAccountBalance(aAccountBalance: CreateAccountBalanceDto) {
accountId, return this.http.post<AccountBalance>(
balance, `/api/v1/account-balance`,
date aAccountBalance
}: { );
accountId: string;
balance: number;
date: Date;
}) {
return this.http.post<AccountBalance>(`/api/v1/account-balance`, {
accountId,
balance,
date
});
} }
public postBenchmark(benchmark: UniqueAsset) { public postBenchmark(benchmark: UniqueAsset) {

@ -1,3 +1,5 @@
import { CreateAccountBalanceDto } from '@ghostfolio/api/app/account-balance/create-account-balance.dto';
import { validateObjectForForm } from '@ghostfolio/client/util/form.util';
import { getLocale } from '@ghostfolio/common/helper'; import { getLocale } from '@ghostfolio/common/helper';
import { AccountBalancesResponse } from '@ghostfolio/common/interfaces'; import { AccountBalancesResponse } from '@ghostfolio/common/interfaces';
@ -60,10 +62,7 @@ export class GfAccountBalancesComponent
@Input() locale = getLocale(); @Input() locale = getLocale();
@Input() showActions = true; @Input() showActions = true;
@Output() accountBalanceCreated = new EventEmitter<{ @Output() accountBalanceCreated = new EventEmitter<CreateAccountBalanceDto>();
balance: number;
date: Date;
}>();
@Output() accountBalanceDeleted = new EventEmitter<string>(); @Output() accountBalanceDeleted = new EventEmitter<string>();
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -107,8 +106,25 @@ export class GfAccountBalancesComponent
} }
} }
public onSubmitAccountBalance() { public async onSubmitAccountBalance() {
this.accountBalanceCreated.emit(this.accountBalanceForm.getRawValue()); const accountBalance: CreateAccountBalanceDto = {
accountId: this.accountId,
balance: this.accountBalanceForm.get('balance').value,
date: this.accountBalanceForm.get('date').value.toISOString()
};
try {
await validateObjectForForm({
classDto: CreateAccountBalanceDto,
form: this.accountBalanceForm,
object: accountBalance
});
} catch (error) {
console.error(error);
return;
}
this.accountBalanceCreated.emit(accountBalance);
} }
public ngOnDestroy() { public ngOnDestroy() {

Loading…
Cancel
Save