From 0244cb29ea48c6e9afdd3661259a76189fc562b2 Mon Sep 17 00:00:00 2001 From: AlineRinquin Date: Wed, 16 Feb 2022 15:20:23 +0100 Subject: [PATCH] ajout contact --- .../page-ajout-contact.component.ts | 5 ++++- .../page-modifier-contact.component.ts | 3 +-- src/app/services/repertoire.service.ts | 11 +++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/app/pages/page-ajout-contact/page-ajout-contact.component.ts b/src/app/pages/page-ajout-contact/page-ajout-contact.component.ts index d65fdec..c6c662c 100644 --- a/src/app/pages/page-ajout-contact/page-ajout-contact.component.ts +++ b/src/app/pages/page-ajout-contact/page-ajout-contact.component.ts @@ -6,6 +6,7 @@ import { Validators, } from '@angular/forms'; import { Router } from '@angular/router'; +import { TokenService } from 'src/app/services/token.service'; import { Contact } from '../../models/contact'; import { RepertoireService } from '../../services/repertoire.service'; @@ -19,6 +20,7 @@ export class PageAjoutContactComponent implements OnInit { constructor( private repertoireService: RepertoireService, + private tokenService: TokenService, private router: Router, private fb: FormBuilder ) { @@ -49,6 +51,7 @@ export class PageAjoutContactComponent implements OnInit { const emailValue = this.ajoutContactForm.value['emailFc']; const dateNaissanceValue = this.ajoutContactForm.value['dateNaissanceFc']; const adresseValue = this.ajoutContactForm.value['adresseFc']; + const teamId = this.tokenService.getCurrentTeamId() const contact: Contact = { id: '', @@ -59,7 +62,7 @@ export class PageAjoutContactComponent implements OnInit { email: emailValue, dateNaissance: dateNaissanceValue, adresse: adresseValue, - team: { id: '1' }, // changer l'id quand la personne est logé => recuperer l'id de la team du membre + team: { id: teamId }, // changer l'id quand la personne est logé => recuperer l'id de la team du membre }; if (contact.nom !== '') { diff --git a/src/app/pages/page-modifier-contact/page-modifier-contact.component.ts b/src/app/pages/page-modifier-contact/page-modifier-contact.component.ts index a9c8b91..fe6c2ad 100644 --- a/src/app/pages/page-modifier-contact/page-modifier-contact.component.ts +++ b/src/app/pages/page-modifier-contact/page-modifier-contact.component.ts @@ -60,7 +60,6 @@ export class PageModifierContactComponent implements OnInit { //Méthode qui initialise les champs du formulaire avec les infos de la BDD private initForm(contact?: Contact): FormGroup { return this.fb.group({ - couleur: [contact ? contact.couleur : ''], firstName: [contact ? contact.nom : ''], lastName: [contact ? contact.prenom : ''], telephone: [contact ? contact.telephone : ''], @@ -72,7 +71,7 @@ export class PageModifierContactComponent implements OnInit { //Méthode qui envoie les champs modifiés pour mise à jour public onSubmit(): void { - const couleurValue = this.modifContactForm.value['couleurFc']; + const couleurValue = this.modifContactForm.value['']; const firstNameValue = this.modifContactForm.value['firstNameFc']; const lastNameValue = this.modifContactForm.value['lastNameFc']; const telephoneValue = this.modifContactForm.value['telephoneFc']; diff --git a/src/app/services/repertoire.service.ts b/src/app/services/repertoire.service.ts index cf9701b..8c85751 100644 --- a/src/app/services/repertoire.service.ts +++ b/src/app/services/repertoire.service.ts @@ -3,6 +3,8 @@ import { HttpClient } from '@angular/common/http'; import { map, Observable } from 'rxjs'; import { environment } from 'src/environments/environment'; import { Contact } from '../models/contact'; +import { Router } from '@angular/router'; +import { TokenService } from './token.service'; @Injectable({ providedIn: 'root', @@ -11,14 +13,15 @@ export class RepertoireService { apiUrl: string; tokenKey: string; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private router: Router, private tokenService: TokenService) { // On se sert des variables d'environnement de notre application this.apiUrl = environment.apiUrl; this.tokenKey = environment.tokenKey; } getContact(): Observable { - return this.http.get(`${this.apiUrl}/contacts/team/1`); + const teamId = this.tokenService.getCurrentTeamId() + return this.http.get(`${this.apiUrl}/contacts/team/${teamId}`); } getContactById(id: any): Observable { @@ -26,7 +29,7 @@ export class RepertoireService { } addContact(contact: Contact): Observable { - console.log(contact); + const teamId = this.tokenService.getCurrentTeamId() return this.http.post(`${this.apiUrl}/contacts/add`, contact); } @@ -35,6 +38,6 @@ export class RepertoireService { } updateContact(contact: Contact): Observable { - return this.http.put(`${this.apiUrl}/contacts/update/1`, contact); + return this.http.put(`${this.apiUrl}/contacts/update/`, contact); } }