2022-01-18 17:12:04 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-03-02 19:14:43 +01:00
|
|
|
import { Router } from '@angular/router';
|
2022-02-16 19:18:24 +01:00
|
|
|
import { MembreService } from 'src/app/services/membre.service';
|
2022-03-02 19:14:43 +01:00
|
|
|
import { TeamService } from 'src/app/services/team.service';
|
|
|
|
import { TokenService } from 'src/app/services/token.service';
|
|
|
|
|
2022-02-25 09:52:06 +01:00
|
|
|
|
2022-01-18 17:12:04 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-page-account',
|
|
|
|
templateUrl: './page-account.component.html',
|
|
|
|
styleUrls: ['./page-account.component.scss']
|
|
|
|
})
|
|
|
|
export class PageAccountComponent implements OnInit {
|
2022-02-16 19:18:24 +01:00
|
|
|
public listMembres: any[];
|
2022-03-02 19:14:43 +01:00
|
|
|
currentUser: any;
|
|
|
|
currentTeam: any;
|
2022-03-06 18:30:50 +01:00
|
|
|
parent: boolean;
|
2022-01-18 17:12:04 +01:00
|
|
|
|
2022-03-02 19:14:43 +01:00
|
|
|
constructor(private membreService: MembreService,
|
|
|
|
private teamService: TeamService,
|
|
|
|
private tokenService: TokenService,
|
|
|
|
private router: Router) {
|
2022-02-16 19:18:24 +01:00
|
|
|
this.listMembres = [];
|
2022-03-06 18:30:50 +01:00
|
|
|
this.parent = false;
|
2022-02-16 19:18:24 +01:00
|
|
|
}
|
2022-01-18 17:12:04 +01:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2022-03-02 19:14:43 +01:00
|
|
|
/** Récuperer la team du membre connecté **/
|
|
|
|
this.teamService.getTeamById()?.subscribe((team) => {
|
|
|
|
this.currentTeam = team;
|
|
|
|
});
|
|
|
|
/** Récuperer le membre connecté **/
|
|
|
|
this.membreService.getMembreId(this.tokenService.getCurrentMembreId()).subscribe((user) => {
|
|
|
|
this.currentUser = user;
|
|
|
|
});
|
|
|
|
/** Récuperer la liste des membres de la team **/
|
2022-02-25 09:52:06 +01:00
|
|
|
this.membreService.getMembresByTeamId()?.subscribe((membres: any[]) => {
|
2022-02-16 19:18:24 +01:00
|
|
|
this.listMembres = membres;
|
2022-03-02 19:14:43 +01:00
|
|
|
});
|
2022-03-06 18:30:50 +01:00
|
|
|
|
|
|
|
/***Gestion des limatations en fonction du role (parent ou enfant) */
|
|
|
|
const roleUser = this.tokenService.getRole();
|
|
|
|
if(roleUser == "ROLE_PARENT"){
|
|
|
|
this.parent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Méthode qui au click va supprimer un contact en faisant appel au service dédié dans Membre Service **/
|
|
|
|
onClickDelete(membreId: number){
|
|
|
|
this.membreService.deleteMembre(membreId).subscribe((resp) => {
|
|
|
|
if(membreId) {
|
|
|
|
this.listMembres.forEach(membreId => console.log(membreId))
|
|
|
|
}else{
|
|
|
|
window.alert("Le profil ne peut pas être supprimé!")
|
|
|
|
}
|
|
|
|
this.router.navigate(['compte/']);
|
|
|
|
});
|
|
|
|
window.location.reload();
|
2022-02-25 09:52:06 +01:00
|
|
|
}
|
2022-01-18 17:12:04 +01:00
|
|
|
}
|