Skip to content

Commit

Permalink
#931: cleanup + calculate isUserMemberOfTeams on-the-fly (no longer c…
Browse files Browse the repository at this point in the history
…ached)
  • Loading branch information
clean-coder committed Jul 29, 2024
1 parent e2dbb27 commit 28c1c52
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import { AlertDialogComponent, AlertDialogData } from '../../shared/dialog/alert
export class DeleteUserComponent implements OnInit {
@Input({ required: true }) user!: User;

private isUserMemberOfTeams: boolean = false;
private isUserOwnerOfKeyResults: boolean = false;
private userHasKeyResults: boolean = false;

constructor(
private readonly userService: UserService,
Expand All @@ -26,29 +25,25 @@ export class DeleteUserComponent implements OnInit {
) {}

ngOnInit() {
this.memberOfTeams(this.user.id);
this.ownerOfKeyResults(this.user.id);
this.userService.isUserOwnerOfKeyResults(this.user).subscribe((booleanAsObject) => {
this.userHasKeyResults = !!booleanAsObject;
});
}

memberOfTeams(userId: number) {
this.isUserMemberOfTeams = this.user.userTeamList != null && this.user.userTeamList.length > 0;
console.log('### member_of_teams', userId, this.isUserMemberOfTeams);
isUserMemberOfTeams(): boolean {
return this.user.userTeamList != null && this.user.userTeamList.length > 0;
}

ownerOfKeyResults(userId: number) {
this.isUserMemberOfTeams = this.user.userTeamList.length > 0;
this.userService.isUserOwnerOfKeyResults(this.user).subscribe((booleanAsObject) => {
this.isUserOwnerOfKeyResults = !!booleanAsObject;
console.log('### key_result', userId, !!booleanAsObject);
});
isUserOwnerOfKeyResults(): boolean {
return this.userHasKeyResults;
}

deleteUser() {
if (this.isUserMemberOfTeams) {
if (this.isUserMemberOfTeams()) {
this.showUnableToDeleteDialog(`${this.userInfo()} ist in Team(s) und kann nicht gelöscht werden!`);
return;
}
if (this.isUserOwnerOfKeyResults) {
if (this.isUserOwnerOfKeyResults()) {
this.showUnableToDeleteDialog(`${this.userInfo()} ist Owner von KeyResults und kann nicht gelöscht werden!`);
return;
}
Expand Down

0 comments on commit 28c1c52

Please sign in to comment.