diff --git a/src/app/pages/page-account/page-account.component.ts b/src/app/pages/page-account/page-account.component.ts index d357828..19a8af8 100644 --- a/src/app/pages/page-account/page-account.component.ts +++ b/src/app/pages/page-account/page-account.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { MembreService } from 'src/app/services/membre.service'; -import { TeamService } from 'src/app/services/team.service'; + @Component({ selector: 'app-page-account', @@ -10,14 +10,15 @@ import { TeamService } from 'src/app/services/team.service'; export class PageAccountComponent implements OnInit { public listMembres: any[]; - constructor(private teamService: TeamService, private membreService: MembreService) { + constructor(private membreService: MembreService) { this.listMembres = []; } ngOnInit(): void { - this.membreService.getMembres().subscribe((membres: any[]) => { + this.membreService.getMembresByTeamId()?.subscribe((membres: any[]) => { + console.log(membres); this.listMembres = membres; - }); - } + }); + } } diff --git a/src/app/pages/page-add-member/page-add-member.component.html b/src/app/pages/page-add-member/page-add-member.component.html index 0447047..b098c43 100644 --- a/src/app/pages/page-add-member/page-add-member.component.html +++ b/src/app/pages/page-add-member/page-add-member.component.html @@ -87,7 +87,20 @@ !addMemberForm.controls['emailFc'].valid }" /> - + + +
+ +
{ + this.membreService.addMembre(membre)?.subscribe((resp) => { this.router.navigate(['compte']); }); } else { diff --git a/src/app/pages/page-creation-team/page-creation-team.component.ts b/src/app/pages/page-creation-team/page-creation-team.component.ts index c7a9ec7..ff3d53e 100644 --- a/src/app/pages/page-creation-team/page-creation-team.component.ts +++ b/src/app/pages/page-creation-team/page-creation-team.component.ts @@ -7,6 +7,7 @@ import { } from '@angular/forms'; import { Router } from '@angular/router'; import { Team } from 'src/app/models/team'; +import { MembreService } from 'src/app/services/membre.service'; import { TeamService } from 'src/app/services/team.service'; @Component({ @@ -18,6 +19,7 @@ export class PageCreationTeamComponent implements OnInit { public teamForm: FormGroup; constructor( private teamService: TeamService, + private membreService: MembreService, private router: Router, private fb: FormBuilder ) { @@ -39,9 +41,6 @@ export class PageCreationTeamComponent implements OnInit { const team: Team = { nom : nameValue, }; - - - if (team.nom !== '' ) { this.teamService.addTeam(team).subscribe((resp) => { this.router.navigate(['compte']); diff --git a/src/app/services/membre.service.ts b/src/app/services/membre.service.ts index 1bdbb08..98d19a0 100644 --- a/src/app/services/membre.service.ts +++ b/src/app/services/membre.service.ts @@ -1,8 +1,10 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { environment } from 'src/environments/environment'; import { Membre } from '../models/membre'; +import { TokenService } from './token.service'; @Injectable({ providedIn: 'root' @@ -11,7 +13,7 @@ export class MembreService { apiUrl: string; tokenKey: string; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private tokenService: TokenService, private router: Router) { this.apiUrl = environment.apiUrl; this.tokenKey = environment.tokenKey; } @@ -20,13 +22,27 @@ export class MembreService { return this.http.get(`${this.apiUrl}/membres/all`); } + getMembresByTeamId(): Observable | void{ + const teamId = this.tokenService.getCurrentTeamId(); + if (teamId){ + return this.http.get(`${this.apiUrl}/membres/team/${teamId}`); + }else { + this.router.navigate(['accueil']); + } + + } + getMembreId(id: any): Observable { return this.http.get(`${this.apiUrl}/membres/` + id); } - addMembre(membre: Membre): Observable { - console.log(membre); - return this.http.post(`${this.apiUrl}/membres/sign-up`, membre); + addMembre(membre: Membre): Observable | void{ + const teamId = this.tokenService.getCurrentTeamId(); + if (teamId){ + return this.http.post(`${this.apiUrl}/membres/add/${teamId}`, membre); + }else { + this.router.navigate(['accueil']); + } } deleteMembre(membre: Membre): Observable { diff --git a/src/app/services/team.service.ts b/src/app/services/team.service.ts index 1aed726..3e96bab 100644 --- a/src/app/services/team.service.ts +++ b/src/app/services/team.service.ts @@ -1,8 +1,10 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; import { Observable } from 'rxjs'; import { environment } from 'src/environments/environment'; import { Team } from '../models/team'; +import { TokenService } from './token.service'; @Injectable({ providedIn: 'root' @@ -12,7 +14,7 @@ export class TeamService { tokenKey: string; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private tokenService: TokenService, private router: Router) { this.apiUrl = environment.apiUrl; this.tokenKey = environment.tokenKey; } @@ -20,8 +22,13 @@ export class TeamService { return this.http.get(`${this.apiUrl}/teams/all`); } - getTeamById(id: any): Observable { - return this.http.get(`${this.apiUrl}/teams/1` + id); + getTeamById(): Observable | void { + const teamId = this.tokenService.getCurrentTeamId(); + if (teamId){ + return this.http.get(`${this.apiUrl}/teams/${teamId}`); + } else { + this.router.navigate(['accueil']); + } } addTeam(team: Team): Observable {