From cf3474f32e634b5e0181e0913d4907d119b3ebbc Mon Sep 17 00:00:00 2001 From: Art Date: Tue, 21 Sep 2021 21:20:30 +0300 Subject: [PATCH] 174. Delete user back end call (#24 Section 25: User Page - Delete User) --- .../src/app/component/user/user.component.html | 2 +- .../src/app/component/user/user.component.ts | 16 ++++++++++++++++ .../src/app/service/user.service.ts | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/support-portal-frontend/src/app/component/user/user.component.html b/support-portal-frontend/src/app/component/user/user.component.html index a5ae6bc..36cc3d1 100644 --- a/support-portal-frontend/src/app/component/user/user.component.html +++ b/support-portal-frontend/src/app/component/user/user.component.html @@ -84,7 +84,7 @@
- +
diff --git a/support-portal-frontend/src/app/component/user/user.component.ts b/support-portal-frontend/src/app/component/user/user.component.ts index 1a662d4..9428437 100644 --- a/support-portal-frontend/src/app/component/user/user.component.ts +++ b/support-portal-frontend/src/app/component/user/user.component.ts @@ -6,6 +6,7 @@ import {NotificationService} from "../../service/notification.service"; import {NotificationType} from "../../notification/notification-type"; import {HttpErrorResponse} from "@angular/common/http"; import {NgForm} from "@angular/forms"; +import {CustomHttpResponse} from "../../dto/custom-http-response"; @Component({ selector: 'app-user', @@ -153,4 +154,19 @@ export class UserComponent implements OnInit, OnDestroy { ); this.subscriptions.push(subscription); } + + onDeleteUser(user: User) { + const subscription = this.userService.deleteUser(user.userId) + .subscribe( + (response: CustomHttpResponse) => { + this.getUsers(false); + this.invalidateVariables(); + this.notificationService.notify(NotificationType.SUCCESS, response.message); + }, + (errorResponse: HttpErrorResponse) => { + this.sendErrorNotification(errorResponse.error.message); + } + ); + this.subscriptions.push(subscription); + } } diff --git a/support-portal-frontend/src/app/service/user.service.ts b/support-portal-frontend/src/app/service/user.service.ts index d9e4c4c..a67b0a5 100644 --- a/support-portal-frontend/src/app/service/user.service.ts +++ b/support-portal-frontend/src/app/service/user.service.ts @@ -46,9 +46,9 @@ export class UserService { }); } - public deleteUser(userId: string): Observable { + public deleteUser(userId: string): Observable { return this.httpClient - .delete(`${this.host}/user/${userId}`); + .delete(`${this.host}/user/${userId}`); } public addUsersToLocalStorage(users: User[]) {