174. Delete user back end call (#24 Section 25: User Page - Delete User)
This commit is contained in:
@ -84,7 +84,7 @@
|
||||
<td class="">
|
||||
<div class="btn-group">
|
||||
<button class="btn btn-outline-info" (click)="onEditUser(appUser)"><i class="fas fa-edit"></i></button>
|
||||
<button class="btn btn-outline-danger"><i class="fas fa-trash"></i></button>
|
||||
<button class="btn btn-outline-danger" (click)="onDeleteUser(appUser)"><i class="fas fa-trash"></i></button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,9 +46,9 @@ export class UserService {
|
||||
});
|
||||
}
|
||||
|
||||
public deleteUser(userId: string): Observable<CustomHttpResponse | HttpErrorResponse> {
|
||||
public deleteUser(userId: string): Observable<CustomHttpResponse> {
|
||||
return this.httpClient
|
||||
.delete<CustomHttpResponse | HttpErrorResponse>(`${this.host}/user/${userId}`);
|
||||
.delete<CustomHttpResponse>(`${this.host}/user/${userId}`);
|
||||
}
|
||||
|
||||
public addUsersToLocalStorage(users: User[]) {
|
||||
|
||||
Reference in New Issue
Block a user