From 9f7fcf7aeb66746869185f7c2014e7dafdcda079 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Thu, 25 Jun 2020 16:21:05 +0530 Subject: [PATCH] feat: savings account actions (delete) (#914) Fixes: #913 --- .../savings-account-view.component.ts | 30 ++++++++++++++++++- src/app/savings/savings.service.ts | 8 +++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/app/savings/savings-account-view/savings-account-view.component.ts b/src/app/savings/savings-account-view/savings-account-view.component.ts index 1088a17f2..fb9e8e14c 100644 --- a/src/app/savings/savings-account-view/savings-account-view.component.ts +++ b/src/app/savings/savings-account-view/savings-account-view.component.ts @@ -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 }); + }); + } + }); + } + } diff --git a/src/app/savings/savings.service.ts b/src/app/savings/savings.service.ts index 9019880b0..feb92880a 100644 --- a/src/app/savings/savings.service.ts +++ b/src/app/savings/savings.service.ts @@ -175,6 +175,14 @@ export class SavingsService { return this.http.put(`/savingsaccounts/${accountId}`, savingsAccount); } + /** + * @param {string} accountId savings account Id + * @returns {Observable} + */ + deleteSavingsAccount(accountId: string): Observable { + return this.http.delete(`/savingsaccounts/${accountId}`); + } + /** * @param {string} accountId Savings Account Id * @param {string} command Command