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,
} 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 !== '') {

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
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'];

View File

@ -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<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> {
@ -26,7 +29,7 @@ export class RepertoireService {
}
addContact(contact: Contact): Observable<any> {
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<any> {
return this.http.put(`${this.apiUrl}/contacts/update/1`, contact);
return this.http.put(`${this.apiUrl}/contacts/update/`, contact);
}
}