ajout contact

This commit is contained in:
AlineRinquin 2022-02-16 15:20:23 +01:00
parent e6f59fb84c
commit 0244cb29ea
3 changed files with 12 additions and 7 deletions

View file

@ -6,6 +6,7 @@ import {
Validators, Validators,
} from '@angular/forms'; } from '@angular/forms';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { TokenService } from 'src/app/services/token.service';
import { Contact } from '../../models/contact'; import { Contact } from '../../models/contact';
import { RepertoireService } from '../../services/repertoire.service'; import { RepertoireService } from '../../services/repertoire.service';
@ -19,6 +20,7 @@ export class PageAjoutContactComponent implements OnInit {
constructor( constructor(
private repertoireService: RepertoireService, private repertoireService: RepertoireService,
private tokenService: TokenService,
private router: Router, private router: Router,
private fb: FormBuilder private fb: FormBuilder
) { ) {
@ -49,6 +51,7 @@ export class PageAjoutContactComponent implements OnInit {
const emailValue = this.ajoutContactForm.value['emailFc']; const emailValue = this.ajoutContactForm.value['emailFc'];
const dateNaissanceValue = this.ajoutContactForm.value['dateNaissanceFc']; const dateNaissanceValue = this.ajoutContactForm.value['dateNaissanceFc'];
const adresseValue = this.ajoutContactForm.value['adresseFc']; const adresseValue = this.ajoutContactForm.value['adresseFc'];
const teamId = this.tokenService.getCurrentTeamId()
const contact: Contact = { const contact: Contact = {
id: '', id: '',
@ -59,7 +62,7 @@ export class PageAjoutContactComponent implements OnInit {
email: emailValue, email: emailValue,
dateNaissance: dateNaissanceValue, dateNaissance: dateNaissanceValue,
adresse: adresseValue, 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 !== '') { if (contact.nom !== '') {

View file

@ -60,7 +60,6 @@ export class PageModifierContactComponent implements OnInit {
//Méthode qui initialise les champs du formulaire avec les infos de la BDD //Méthode qui initialise les champs du formulaire avec les infos de la BDD
private initForm(contact?: Contact): FormGroup { private initForm(contact?: Contact): FormGroup {
return this.fb.group({ return this.fb.group({
couleur: [contact ? contact.couleur : ''],
firstName: [contact ? contact.nom : ''], firstName: [contact ? contact.nom : ''],
lastName: [contact ? contact.prenom : ''], lastName: [contact ? contact.prenom : ''],
telephone: [contact ? contact.telephone : ''], telephone: [contact ? contact.telephone : ''],
@ -72,7 +71,7 @@ export class PageModifierContactComponent implements OnInit {
//Méthode qui envoie les champs modifiés pour mise à jour //Méthode qui envoie les champs modifiés pour mise à jour
public onSubmit(): void { public onSubmit(): void {
const couleurValue = this.modifContactForm.value['couleurFc']; const couleurValue = this.modifContactForm.value[''];
const firstNameValue = this.modifContactForm.value['firstNameFc']; const firstNameValue = this.modifContactForm.value['firstNameFc'];
const lastNameValue = this.modifContactForm.value['lastNameFc']; const lastNameValue = this.modifContactForm.value['lastNameFc'];
const telephoneValue = this.modifContactForm.value['telephoneFc']; const telephoneValue = this.modifContactForm.value['telephoneFc'];

View file

@ -3,6 +3,8 @@ import { HttpClient } from '@angular/common/http';
import { map, Observable } from 'rxjs'; import { map, Observable } from 'rxjs';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Contact } from '../models/contact'; import { Contact } from '../models/contact';
import { Router } from '@angular/router';
import { TokenService } from './token.service';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@ -11,14 +13,15 @@ export class RepertoireService {
apiUrl: string; apiUrl: string;
tokenKey: 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 // On se sert des variables d'environnement de notre application
this.apiUrl = environment.apiUrl; this.apiUrl = environment.apiUrl;
this.tokenKey = environment.tokenKey; this.tokenKey = environment.tokenKey;
} }
getContact(): Observable<any> { getContact(): Observable<any> {
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<any> { getContactById(id: any): Observable<any> {
@ -26,7 +29,7 @@ export class RepertoireService {
} }
addContact(contact: Contact): Observable<any> { addContact(contact: Contact): Observable<any> {
console.log(contact); const teamId = this.tokenService.getCurrentTeamId()
return this.http.post(`${this.apiUrl}/contacts/add`, contact); return this.http.post(`${this.apiUrl}/contacts/add`, contact);
} }
@ -35,6 +38,6 @@ export class RepertoireService {
} }
updateContact(contact: Contact): Observable<any> { updateContact(contact: Contact): Observable<any> {
return this.http.put(`${this.apiUrl}/contacts/update/1`, contact); return this.http.put(`${this.apiUrl}/contacts/update/`, contact);
} }
} }