From 390b670be573d540dfcdcc5c256b04e755f6025c Mon Sep 17 00:00:00 2001 From: piratefinn <toyou1995@gmail.com> Date: Tue, 20 Mar 2018 17:29:00 +0000 Subject: [PATCH] fully working transaction edit and delete --- .../dashboard/transaction-log.component.html | 2 +- .../dashboard/transaction-log.component.ts | 28 ++++++++++++++++++- src/app/providers/api-service.ts | 12 +++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/app/dashboard/transaction-log.component.html b/src/app/dashboard/transaction-log.component.html index 0638a50..09ced33 100644 --- a/src/app/dashboard/transaction-log.component.html +++ b/src/app/dashboard/transaction-log.component.html @@ -122,7 +122,7 @@ <div class="col-md-12"> <div [ngSwitch]="transactionFormStatus"> <div *ngSwitchCase="'success'" class="alert alert-success" role="alert"> - Edit Succeeded. + {{transactionFormStatusSuccess}} </div> <div *ngSwitchCase="'send_failed'" class="alert alert-danger" role="alert"> {{transactionFormStatusError}} diff --git a/src/app/dashboard/transaction-log.component.ts b/src/app/dashboard/transaction-log.component.ts index e9e10ce..580a4a9 100644 --- a/src/app/dashboard/transaction-log.component.ts +++ b/src/app/dashboard/transaction-log.component.ts @@ -26,6 +26,7 @@ export class TransactionLogComponent implements OnInit { categoryList: any; categoryNameList: string[] = []; transactionFormStatus: string; + transactionFormStatusSuccess: string; transactionFormStatusError = 'Error received, please try again.'; public paginateConfig: PaginationInstance = { @@ -137,7 +138,32 @@ export class TransactionLogComponent implements OnInit { } deleteRecurringTransaction() { - + let myParams = { + id: this.clickedRecur.id, + }; + this.api + .recurDelete(myParams) + .subscribe( + result => { + if ( result.success === true ) { + this.transactionFormStatus = 'success'; + this.transactionFormStatusSuccess = 'Delete Succeeded.'; + } else { + this.transactionFormStatusError = JSON.stringify(result.status) + 'Error, ' + JSON.stringify(result.message); + this.transactionFormStatus = 'send_failed'; + } + }, + error => { + console.log(error); + try { + console.log(error.error); + this.transactionFormStatusError = '"' + error.error.error + '" Error, ' + error.error.message; + } catch (e) { + this.transactionFormStatusError = 'There was a server error, please try again later.'; + } + this.transactionFormStatus = 'send_failed'; + } + ); } } diff --git a/src/app/providers/api-service.ts b/src/app/providers/api-service.ts index 519d272..a77a68c 100644 --- a/src/app/providers/api-service.ts +++ b/src/app/providers/api-service.ts @@ -158,7 +158,7 @@ export class ApiService { ); } - // Uploads a transaction + // Edits a recurring transaction public recurUpdate(data) { data.session_key = this.sessionKey; @@ -168,6 +168,16 @@ export class ApiService { ); } + // Edits a recurring transaction + + public recurDelete(data) { + data.session_key = this.sessionKey; + return this.http.post<any>( + this.apiUrl + '/recurring-transactions/delete', + data + ); + } + // gets payroll list for log public payrollList(data) {