feat: savings account actions (delete) (#914)

Fixes: #913
This commit is contained in:
Karan Takalkar
2020-06-25 16:21:05 +05:30
committed by GitHub
parent a3891e7946
commit 9f7fcf7aeb
2 changed files with 37 additions and 1 deletions
@@ -1,9 +1,14 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from '@angular/material';
/** Custom Dialogs */
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
/** Custom Buttons Configuration */
import { SavingsButtonsConfiguration } from './savings-buttons.config';
import { SavingsService } from '../savings.service';
/**
* Savings Account View Component
@@ -25,9 +30,13 @@ export class SavingsAccountViewComponent implements OnInit {
/**
* Fetches savings account data from `resolve`
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SavingsService} savingsService Savings Service
*/
constructor(private route: ActivatedRoute,
private router: Router) {
private router: Router,
private savingsService: SavingsService,
public dialog: MatDialog) {
this.route.data.subscribe((data: { savingsAccountData: any, savingsDatatables: any }) => {
this.savingsAccountData = data.savingsAccountData;
this.savingsDatatables = data.savingsDatatables;
@@ -96,7 +105,26 @@ export class SavingsAccountViewComponent implements OnInit {
case 'Modify Application':
this.router.navigate(['edit-savings-account'], { relativeTo: this.route });
break;
case 'Delete':
this.deleteSavingsAccount();
break;
}
}
/**
* Deletes Savings Account.
*/
private deleteSavingsAccount() {
const deleteSavingsAccountDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `savings account with id: ${this.savingsAccountData.id}` }
});
deleteSavingsAccountDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.savingsService.deleteSavingsAccount(this.savingsAccountData.id).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
});
}
}
+8
View File
@@ -175,6 +175,14 @@ export class SavingsService {
return this.http.put(`/savingsaccounts/${accountId}`, savingsAccount);
}
/**
* @param {string} accountId savings account Id
* @returns {Observable<any>}
*/
deleteSavingsAccount(accountId: string): Observable<any> {
return this.http.delete(`/savingsaccounts/${accountId}`);
}
/**
* @param {string} accountId Savings Account Id
* @param {string} command Command