Ajout des headers dans les services avec quelques tests (il est préférable d'avoir accès à la base de données pour le reste des tests)

master
Yanaël GRETTE 4 years ago
parent 7ebba40014
commit 9c85714fd6
  1. 33
      src/app/home/home-assistante/home-assistante.component.ts
  2. 109
      src/app/home/home.component.ts
  3. 4
      src/app/modeles/modele-collaborateur.ts
  4. 4
      src/app/modeles/modele-ep.ts
  5. 8
      src/app/modeles/modele-formation.ts
  6. 14
      src/app/service/service-collaborateur.ts
  7. 50
      src/app/service/service-ep.ts
  8. 56
      src/app/service/service-formation.ts
  9. 3
      src/environments/environment.ts

@ -1,8 +1,5 @@
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
import { ServiceCollaborateur } from "../../service";
import { CollaborateurModel } from "../../modeles/modele-collaborateur";
@Component({ @Component({
selector : 'home-assistante', selector : 'home-assistante',
@ -10,39 +7,17 @@ import { CollaborateurModel } from "../../modeles/modele-collaborateur";
}) })
export class HomeAssistanteComponent implements OnInit { export class HomeAssistanteComponent implements OnInit {
private collabListSubscription : Subscription;
private collab1Subscription : Subscription; constructor() {
private collab2Subscription : Subscription;
private listeCollaborateurs : CollaborateurModel[];
constructor(private serviceCollaborateur : ServiceCollaborateur) {
this.collabListSubscription = this.serviceCollaborateur.listeCollaborateurs().
subscribe(collaborateurs => this.test(collaborateurs));
let params = { mail : "angelique@apside.com"};
this.collab1Subscription = this.serviceCollaborateur.getCollaborateurByParam(params).
subscribe(collaborateurs => this.test2(collaborateurs));
let params2 = { id : 1 };
this.collab2Subscription = this.serviceCollaborateur.getCollaborateurByParam(params2).
subscribe(collaborateurs => this.test2(collaborateurs));
} }
test(collaborateurs) {
for(let collaborateur of collaborateurs) {
console.log(collaborateur);
}
}
test2(collaborateur) {
console.log(collaborateur);
}
ngOnInit() { ngOnInit() {
} }
ngOnDestroy() {
if(this.collabListSubscription != null) {
this.collabListSubscription.unsubscribe();
}
}
} }

@ -1,6 +1,13 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { KeycloakService } from 'keycloak-angular'; import { KeycloakService } from 'keycloak-angular';
import { Observable, Subscription } from 'rxjs';
import { ServiceCollaborateur, ServiceFormation, ServiceEP } from "../service";
import { CollaborateurModel } from "../modeles/modele-collaborateur";
import { FormationModel } from "../modeles/modele-formation";
import { EpModel } from "../modeles/modele-ep";
/* /*
import { HomeAssistanteComponent } from './home-assistante/home-assistante.component'; import { HomeAssistanteComponent } from './home-assistante/home-assistante.component';
@ -18,12 +25,112 @@ import { Role } from '../utils/roles';
export class HomeComponent implements OnInit { export class HomeComponent implements OnInit {
role = Role; role = Role;
constructor(public keycloakService : KeycloakService) { /*private collabListSubscription : Subscription;
private collab1Subscription : Subscription;
private collab2Subscription : Subscription;
private listeCollaborateurs : CollaborateurModel[];
private formationSubscription : Subscription;
private addFormationSubscription : Subscription;
*/
private epEnvoieSubscription : Subscription;
private epCollaborateurSubscription : Subscription;
private epDisponiblesSubscription : Subscription;
private epCollaborateurProchain : Subscription;
constructor(public keycloakService : KeycloakService, private serviceCollaborateur : ServiceCollaborateur,
private serviceFormation : ServiceFormation, private serviceEP : ServiceEP) {
//********TEST********//
let ep = new EpModel();
ep.id = 10;
ep.type ="EPA";
//ep.dateDisponibilite = new Date(2020,0,5,25,30);
ep.dateDisponibilite = new Date(2020,0,0,25,30);
ep.etat = "créer";
let collaborateur = new CollaborateurModel();
collaborateur.id = 1;
collaborateur.nom = "GRETTE";
collaborateur.prenom = "Yanaël";
collaborateur.mail = "yanael.grette@apside-groupe.com";
collaborateur.agence = "Orléans";
collaborateur.fonction = "Stagiaire";
ep.collaborateur = collaborateur;
this.epEnvoieSubscription = this.serviceEP.envoieEP(ep, "saisie").
subscribe(eps => this.display(eps));
//this.epCollaborateurProchain = this.serviceEP.prochainEPCollaborateur(3).
//subscribe(eps => this.display(eps));
//this.epCollaborateurSubscription = this.serviceEP.listeEPCollaborateur(1).
//subscribe(eps => this.display(eps));
//this.epDisponiblesSubscription = this.serviceEP.listeEPDisponibles().
// subscribe(eps => this.display(eps));
/*
let formation = new FormationModel();
formation.intitule = "TestJAVA";
formation.dateDebut = new Date("10-12-2020");
formation.dateFin = new Date("10-12-2020");
formation.statut = "Prévue";
formation.lieu = "Orléans";
formation.duree = 5;
formation.organisme = "Apside";
formation.nomFormateur = "Patrick";
console.log(formation.dateDebut);
this.addFormationSubscription = this.serviceFormation.nouvelleFormation(formation)
.subscribe();
this.formationSubscription = this.serviceFormation.listeFormations()
.subscribe(formations=> this.display(formations));
/*
this.collabListSubscription = this.serviceCollaborateur.listeCollaborateurs(token).
subscribe(collaborateurs => this.test(collaborateurs));
let params = { mail : "angelique@apside.com"};
this.collab1Subscription = this.serviceCollaborateur.getCollaborateurByParam(token,params).
subscribe(collaborateurs => this.test2(collaborateurs));
let params2 = { id : 1 };
this.collab2Subscription = this.serviceCollaborateur.getCollaborateurByParam(token,params2).
subscribe(collaborateurs => this.test2(collaborateurs));
console.log(token);*
//*/
} }
display(listes) {
for(let l of listes) {
console.log(l);
}
}
/*
test2(collaborateur) {
console.log(collaborateur);
}
*/
ngOnInit() { ngOnInit() {
} }
ngOnDestroy() {
/*if(this.collabListSubscription != null) {
this.collabListSubscription.unsubscribe();
}*/
/*
if(this.formationSubscription != null) {
this.formationSubscription.unsubscribe();
}
if(this.addFormationSubscription != null) {
this.addFormationSubscription.unsubscribe();
}
*/
if(this.epEnvoieSubscription != null) {
this.epEnvoieSubscription.unsubscribe();
}
if(this.epCollaborateurSubscription != null) {
this.epCollaborateurSubscription.unsubscribe();
}
if(this.epDisponiblesSubscription != null) {
this.epDisponiblesSubscription.unsubscribe();
}
if(this.epCollaborateurProchain != null) {
this.epCollaborateurProchain.unsubscribe();
}
}
} }

@ -2,8 +2,8 @@ export class CollaborateurModel {
id? : number; id? : number;
nom? : string; nom? : string;
prenom? : string; prenom? : string;
adresse? : string;
agence? : string;
mail? : string; mail? : string;
agence? : string;
dateEmbauche? : Date;
fonction? : string; fonction? : string;
}; };

@ -1,7 +1,7 @@
import { CollaborateurModel } from "./modele-collaborateur"; import { CollaborateurModel } from "./modele-collaborateur";
export interface EpModel { export class EpModel {
idEp? : number; id? : number;
type? : string; type? : string;
dateDisponibilite? : Date; dateDisponibilite? : Date;
dateSaisie? : Date; dateSaisie? : Date;

@ -1,5 +1,5 @@
export interface FormationModel { export class FormationModel {
idFormation? : number; id? : number;
intitule? : string; intitule? : string;
dateDebut? : Date; dateDebut? : Date;
dateFin? : Date; dateFin? : Date;
@ -11,7 +11,7 @@ export interface FormationModel {
}; };
export interface DemandeFormationModel { export class DemandeFormationModel {
idDemandeFormation? : number; idDemandeFormation? : number;
idEp? : number; idEp? : number;
statut? : string; statut? : string;
@ -26,6 +26,6 @@ export interface ThemeModel {
nom : string; nom : string;
}; };
export interface EvaluationFormationModel { export class EvaluationFormationModel {
//TODO //TODO
} }

@ -2,6 +2,10 @@ import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { KeycloakService } from 'keycloak-angular';
import { urlCollaborateur } from "../utils/path-values-collaborateurs"; import { urlCollaborateur } from "../utils/path-values-collaborateurs";
import { CollaborateurModel } from "../modeles/modele-collaborateur"; import { CollaborateurModel } from "../modeles/modele-collaborateur";
@ -9,15 +13,19 @@ import { CollaborateurModel } from "../modeles/modele-collaborateur";
providedIn : 'root' providedIn : 'root'
}) })
export class ServiceCollaborateur { export class ServiceCollaborateur {
constructor(private http: HttpClient) { constructor(private http: HttpClient, private keycloakService : KeycloakService) {
} }
listeCollaborateurs() : Observable<CollaborateurModel[]> { listeCollaborateurs() : Observable<CollaborateurModel[]> {
return this.http.get<CollaborateurModel[]>(urlCollaborateur); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<CollaborateurModel[]>(urlCollaborateur, { headers });
} }
getCollaborateurByParam(params) : Observable<CollaborateurModel> { getCollaborateurByParam(params) : Observable<CollaborateurModel> {
return this.http.get<CollaborateurModel>(urlCollaborateur, { params }); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<CollaborateurModel>(urlCollaborateur, { params, headers });
} }
} }

@ -2,6 +2,8 @@ import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { KeycloakService } from 'keycloak-angular';
import { urlsEP } from "../utils/path-values-ep"; import { urlsEP } from "../utils/path-values-ep";
import { EpModel, RDVEntretienModel } from "../modeles/modele-ep"; import { EpModel, RDVEntretienModel } from "../modeles/modele-ep";
@ -9,51 +11,73 @@ import { EpModel, RDVEntretienModel } from "../modeles/modele-ep";
providedIn : 'root' providedIn : 'root'
}) })
export class ServiceEP { export class ServiceEP {
constructor(private http: HttpClient) { constructor(private http: HttpClient, private keycloakService : KeycloakService) {}
}
listeProchainsEPReferent(id) : Observable<EpModel[]> { listeProchainsEPReferent(id) : Observable<EpModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
let params = { idReferent : id }; let params = { idReferent : id };
return this.http.get<EpModel[]>(urlsEP.prochainsEPReferent, { params }); const headers = { Authorization: "Bearer "+token };
return this.http.get<EpModel[]>(urlsEP.prochainsEPReferent, { params, headers });
} }
listeEPDisponibles() : Observable<EpModel[]> { listeEPDisponibles() : Observable<EpModel[]> {
return this.http.get<EpModel[]>(urlsEP.epDisponibles); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<EpModel[]>(urlsEP.epDisponibles, {headers});
} }
listeEPCollaborateur(id) : Observable<EpModel[]> { listeEPCollaborateur(id) : Observable<EpModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
let params = { idCollab : id }; let params = { idCollab : id };
return this.http.get<EpModel[]>(urlsEP.epCollaborateur, {params}); const headers = { Authorization: "Bearer "+token };
return this.http.get<EpModel[]>(urlsEP.epCollaborateur, {params, headers});
} }
listeEPReferent(id) : Observable<EpModel[]> { listeEPReferent(id) : Observable<EpModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
let params = { idReferent : id }; let params = { idReferent : id };
return this.http.get<EpModel[]>(urlsEP.epReferent); const headers = { Authorization: "Bearer "+token };
return this.http.get<EpModel[]>(urlsEP.epReferent, { params, headers});
} }
prochainEPCollaborateur(id) : Observable<EpModel> { prochainEPCollaborateur(id) : Observable<EpModel> {
let token = this.keycloakService.getKeycloakInstance().token;
let params = { idCollab : id }; let params = { idCollab : id };
return this.http.get<EpModel>(urlsEP.prochainEpCollaborateur); const headers = { Authorization: "Bearer "+token };
return this.http.get<EpModel>(urlsEP.prochainEpCollaborateur, { params, headers});
} }
envoieEP(ep : EpModel, action) { envoieEP(ep : EpModel, action) {
let params = { action : action }; let token = this.keycloakService.getKeycloakInstance().token;
return this.http.post<EpModel>(urlsEP.envoieEP, ep, {params}); let params = { action };
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.put<EpModel>(urlsEP.envoieEP, ep, {params, headers});
} }
propositionDate(dates) { propositionDate(dates) {
return this.http.post<RDVEntretienModel>(urlsEP.propositionDate, dates); let token = this.keycloakService.getKeycloakInstance().token;
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.post<RDVEntretienModel>(urlsEP.propositionDate, dates, {headers});
} }
rappelerSignature(id) { rappelerSignature(id) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idEp : id }; let params = { idEp : id };
return this.http.get(urlsEP.rappelSignature, {params}); return this.http.post(urlsEP.rappelSignature, null, {params, headers});
} }
demandeEPI(id) { demandeEPI(id) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { IdCollab : id }; let params = { IdCollab : id };
return this.http.post(urlsEP.epi, params); return this.http.post(urlsEP.epi, null, { params, headers});
} }

@ -2,6 +2,8 @@ import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http"; import { HttpClient } from "@angular/common/http";
import { Observable } from "rxjs"; import { Observable } from "rxjs";
import { KeycloakService } from 'keycloak-angular';
import {FormationModel, DemandeFormationModel, EvaluationFormationModel, ThemeModel } from "../modeles/modele-formation"; import {FormationModel, DemandeFormationModel, EvaluationFormationModel, ThemeModel } from "../modeles/modele-formation";
import { urlsFormation } from "../utils/path-values-formations"; import { urlsFormation } from "../utils/path-values-formations";
@ -9,53 +11,79 @@ import { urlsFormation } from "../utils/path-values-formations";
providedIn : 'root' providedIn : 'root'
}) })
export class ServiceFormation { export class ServiceFormation {
constructor(private http: HttpClient) { constructor(private http: HttpClient, private keycloakService : KeycloakService) {}
}
listeFormations() : Observable<FormationModel[]> { listeFormations() : Observable<FormationModel[]> {
return this.http.get<FormationModel[]>(urlsFormation.urlFormation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<FormationModel[]>(urlsFormation.urlFormation, {headers});
} }
listeFormationsCollaborateur(id) : Observable<FormationModel[]> { listeFormationsCollaborateur(id) : Observable<FormationModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idCollab : id }; let params = { idCollab : id };
return this.http.get<FormationModel[]>(urlsFormation.urlFormation, { params }); return this.http.get<FormationModel[]>(urlsFormation.urlFormation, { params, headers });
} }
nouvelleFormation(formation) : Observable<FormationModel> { nouvelleFormation(formation) : Observable<FormationModel> {
return this.http.post<FormationModel>(urlsFormation.newFormation, formation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.post<FormationModel>(urlsFormation.newFormation, formation, {headers});
} }
updateFormation(formation) : Observable<FormationModel> { updateFormation(formation) : Observable<FormationModel> {
return this.http.post<FormationModel>(urlsFormation.newFormation, formation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.put<FormationModel>(urlsFormation.newFormation, formation, {headers});
} }
deleteFormation(id) { deleteFormation(id) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idFormation : id }; let params = { idFormation : id };
return this.http.delete(urlsFormation.urlFormation); return this.http.delete(urlsFormation.urlFormation, {headers, params});
} }
evaluationsFormation(id) : Observable<EvaluationFormationModel[]> { evaluationsFormation(id) : Observable<EvaluationFormationModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idFormation : id }; let params = { idFormation : id };
return this.http.get<EvaluationFormationModel[]>(urlsFormation.evaluationsFormation); return this.http.get<EvaluationFormationModel[]>(urlsFormation.evaluationsFormation, {headers, params});
} }
evaluerFormation(evaluation) { evaluerFormation(evaluation) {
return this.http.post<EvaluationFormationModel>(urlsFormation.evaluerFormation, evaluation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.post<EvaluationFormationModel>(urlsFormation.evaluerFormation, evaluation, {headers});
} }
listeDemandesFormation() : Observable<DemandeFormationModel[]> { listeDemandesFormation() : Observable<DemandeFormationModel[]> {
return this.http.get<DemandeFormationModel[]>(urlsFormation.urlDemandesFormation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<DemandeFormationModel[]>(urlsFormation.urlDemandesFormation, {headers});
} }
reponseDemandeFormation(demandeFormation) { reponseDemandeFormation(demandeFormation) {
return this.http.post<DemandeFormationModel>(urlsFormation.urlDemandesFormation, demandeFormation); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.post<DemandeFormationModel>(urlsFormation.urlDemandesFormation, demandeFormation, {headers});
} }
listeTheme() : Observable<ThemeModel[]> { listeTheme() : Observable<ThemeModel[]> {
return this.http.get<ThemeModel[]>(urlsFormation.urlTheme); let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
return this.http.get<ThemeModel[]>(urlsFormation.urlTheme, {headers});
} }
} }

@ -12,8 +12,7 @@ const keycloakConfig: KeycloakConfig = {
}; };
const serveurConfig = { const serveurConfig = {
url : "http://localhost:3000" url : "http://localhost:3000/api"
//url : "http:localhost:3000/api"
} }
export const environment = { export const environment = {

Loading…
Cancel
Save