Skip to content
Snippets Groups Projects
Commit bd6adb07 authored by David Stäheli's avatar David Stäheli
Browse files

update post transaction :smile:

parent dd14a305
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ import { AccountsService } from '../../services/accounts.service';
import { isBlank } from '@app/core';
import { Account } from '../../models/account';
import { TransactionService } from '../../services/transaction.service';
import { MatSnackBar } from '@angular/material/snack-bar';
@Component({
selector: 'wed-new-transaction',
......@@ -38,7 +39,8 @@ export class NewTransactionComponent implements OnInit {
constructor(
private _formBuilder: FormBuilder,
private accountsService: AccountsService,
private transactionService: TransactionService
private transactionService: TransactionService,
private _snackBar: MatSnackBar
) {}
ngOnInit() {
......@@ -81,13 +83,36 @@ export class NewTransactionComponent implements OnInit {
}
submit(): void {
console.log(
`submit form to: ${this.toFormControl.value}, amount: ${this.amountFormControl.value}`
);
const toValue = this.toFormControl.value || 0;
const amountValue = this.amountFormControl.value || 0;
// TODO notification service
//this.subscriptions.push(this.transactionService.createTransaction(toValue, amountValue).subscribe());
this.subscriptions.push(
this.transactionService.createTransaction(toValue, amountValue).subscribe(
res => {
if (res === null) {
this._snackBar.open(
`Whoops, da ist etwas schief gelaufen`,
'Oooch',
{
duration: 3500,
}
);
return;
}
this._snackBar.open(
`Cool, Sie haben ${amountValue} CHF versendet`,
'Awesome',
{ duration: 3500 }
);
this.form.reset();
},
error => {
console.log(error);
this._snackBar.open(`Whoops, da ist etwas schief gelaufen`, 'Oooch', {
duration: 3500,
});
}
)
);
}
}
......@@ -58,15 +58,14 @@ export class TransactionResourceService extends ResourceBase {
}
public postTransaction(
to: Number,
amount: Number,
to: Number
): Observable<Transaction | null> {
// {target, amount}
): Observable<any | null> {
return this.post('/accounts/transactions', {
target: to,
amount: amount,
}).pipe(
map((result: Transaction) => {
map((result: any) => {
if (result) {
return result;
}
......
......@@ -22,7 +22,7 @@ export class TransactionService {
return this.transactionResource.getTransactions(query);
}
createTransaction(amount: Number, to: Number): Observable<any> {
return this.transactionResource.postTransaction(amount, to);
createTransaction(to: Number, amount: Number): Observable<any> {
return this.transactionResource.postTransaction(to, amount);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment