Is there a more efficient way to remove an alert only if it is not assigned to any user? Currently, I am checking my users list and filtering out the users who have this alert assigned using observables. But I wonder if there is a better approach to achieve this task.
deleteAlert(id: number) {
this.usersService.getUsers().subscribe(
(users) => {
if (users.filter((value) => value.alert.id === id).length > 0) {
console.log('Deassign alert from all users first');
} else {
this.alertService.deleteVillain(id)
.subscribe(() => {
this.alertsList =this.alertsList.filter(alerts=>alerts.id!==id);
});
}
}
)}