add member avec role ok account récupère les membre en focntion de la team
This commit is contained in:
parent
7784870446
commit
466a146174
@ -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;
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,20 @@
|
||||
!addMemberForm.controls['emailFc'].valid
|
||||
}"
|
||||
/>
|
||||
<label for="floatingInputemail">VOTRE EMAIL</label>
|
||||
<label for="floatingInputemail">Votre Email</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<select
|
||||
class="form-control"
|
||||
id="floatingInputRole"
|
||||
placeholder=""
|
||||
name="Role"
|
||||
formControlName="roleFc"
|
||||
>
|
||||
<option value="ROLE_PARENT">Adulte</option>
|
||||
<option value="ROLE_ENFANT">Enfant</option>
|
||||
</select>
|
||||
<label value="ROLE_PARENT">Sélectionner un profil</label>
|
||||
</div>
|
||||
<div class="form-floating">
|
||||
<input
|
||||
|
@ -29,6 +29,7 @@ export class PageAddMemberComponent implements OnInit {
|
||||
firstNameFc: new FormControl('', [Validators.required]),
|
||||
lastNameFc: new FormControl('', [Validators.required]),
|
||||
dateNaissanceFc: new FormControl('', [Validators.required]),
|
||||
roleFc: new FormControl('', []),
|
||||
couleurFc: new FormControl('', []),
|
||||
emailFc: new FormControl('', [
|
||||
Validators.email,
|
||||
@ -56,6 +57,7 @@ export class PageAddMemberComponent implements OnInit {
|
||||
const firstNameValue = this.addMemberForm.value['firstNameFc'];
|
||||
const lastNameValue = this.addMemberForm.value['lastNameFc'];
|
||||
const emailValue = this.addMemberForm.value['emailFc'];
|
||||
const roleValue = this.addMemberForm.value['roleFc'];
|
||||
const passwordValue = this.addMemberForm.value['passwordFc'];
|
||||
const dateNaissanceValue = this.addMemberForm.value['dateNaissanceFc'];
|
||||
const couleurValue = this.addMemberForm.value['couleurFc'];
|
||||
@ -70,12 +72,12 @@ export class PageAddMemberComponent implements OnInit {
|
||||
couleur: couleurValue,
|
||||
dateNaissance: dateNaissanceValue,
|
||||
passwordConfirm: passwordConfirmValue,
|
||||
roleList: ["ROLE_PARENT"]
|
||||
roleList: [roleValue]
|
||||
};
|
||||
|
||||
|
||||
if (membre.email !== '' && membre.password !== '') {
|
||||
this.membreService.addMembre(membre).subscribe((resp) => {
|
||||
this.membreService.addMembre(membre)?.subscribe((resp) => {
|
||||
this.router.navigate(['compte']);
|
||||
});
|
||||
} else {
|
||||
|
@ -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']);
|
||||
|
@ -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<any> | 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<any> {
|
||||
return this.http.get(`${this.apiUrl}/membres/` + id);
|
||||
}
|
||||
|
||||
addMembre(membre: Membre): Observable<any> {
|
||||
console.log(membre);
|
||||
return this.http.post(`${this.apiUrl}/membres/sign-up`, membre);
|
||||
addMembre(membre: Membre): Observable<any> | 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<any> {
|
||||
|
@ -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<any> {
|
||||
return this.http.get(`${this.apiUrl}/teams/1` + id);
|
||||
getTeamById(): Observable<any> | 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<any> {
|
||||
|
Loading…
Reference in New Issue
Block a user