From b7e4e1ad1845ebe3b6d46b605044054dcd825c6d Mon Sep 17 00:00:00 2001 From: Sana EL HIRI Date: Sun, 6 Mar 2022 18:30:50 +0100 Subject: [PATCH] =?UTF-8?q?avanc=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page-account/page-account.component.ts | 21 +++++++++++++++++++ .../page-delete-member.component.html | 3 +-- .../page-delete-member.component.ts | 17 +++++++++++++-- src/app/services/membre.service.ts | 4 ++-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/app/pages/page-account/page-account.component.ts b/src/app/pages/page-account/page-account.component.ts index 0814759..a368213 100644 --- a/src/app/pages/page-account/page-account.component.ts +++ b/src/app/pages/page-account/page-account.component.ts @@ -15,12 +15,14 @@ export class PageAccountComponent implements OnInit { public listMembres: any[]; currentUser: any; currentTeam: any; + parent: boolean; constructor(private membreService: MembreService, private teamService: TeamService, private tokenService: TokenService, private router: Router) { this.listMembres = []; + this.parent = false; } ngOnInit(): void { @@ -36,5 +38,24 @@ export class PageAccountComponent implements OnInit { this.membreService.getMembresByTeamId()?.subscribe((membres: any[]) => { this.listMembres = membres; }); + + /***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(); } } diff --git a/src/app/pages/page-delete-member/page-delete-member.component.html b/src/app/pages/page-delete-member/page-delete-member.component.html index 85ce3ef..df389ce 100644 --- a/src/app/pages/page-delete-member/page-delete-member.component.html +++ b/src/app/pages/page-delete-member/page-delete-member.component.html @@ -22,8 +22,7 @@ id = "bouton-ajout" type="button" class="btn btn-primary btn-lg bouton-oui" - - + (clickDelete)="onClickDelete($event)" >Oui, je souhaite supprimer ce compte diff --git a/src/app/pages/page-delete-member/page-delete-member.component.ts b/src/app/pages/page-delete-member/page-delete-member.component.ts index 34b589f..e52310e 100644 --- a/src/app/pages/page-delete-member/page-delete-member.component.ts +++ b/src/app/pages/page-delete-member/page-delete-member.component.ts @@ -1,4 +1,6 @@ import { Component, EventEmitter, OnInit, Output } from '@angular/core'; +import { Router } from '@angular/router'; +import { Membre } from 'src/app/models/membre'; import { MembreService } from 'src/app/services/membre.service'; import { TokenService } from 'src/app/services/token.service'; @@ -11,12 +13,23 @@ export class PageDeleteMemberComponent implements OnInit { @Output() clickDelete = new EventEmitter(); parent: boolean; - constructor(private tokenService: TokenService, private membreService: MembreService) { - this.parent = false; + constructor(private membreService: MembreService, private tokenService: TokenService) { + this.parent = false; + } ngOnInit(): void { + const roleUser = this.tokenService.getRole(); + + if(roleUser == "ROLE_PARENT"){ + this.parent = true; + } + } + onClickDelete(membreId: any){ + window.alert("Le profil à bien été supprimé!") + this.clickDelete.emit(membreId); + } } diff --git a/src/app/services/membre.service.ts b/src/app/services/membre.service.ts index 105aa78..ff88d34 100644 --- a/src/app/services/membre.service.ts +++ b/src/app/services/membre.service.ts @@ -45,8 +45,8 @@ export class MembreService { } } - deleteMembre(membre: Membre): Observable{ - return this.http.delete(`${this.apiUrl}/membres/delete/${membre.id}`); + deleteMembre(membreId: number): Observable{ + return this.http.delete(`${this.apiUrl}/membres/delete/${membreId}`); } updateMembre(membre: Membre): Observable | void {