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 5 years ago
parent 7ebba40014
commit 9c85714fd6
  1. 33
      src/app/home/home-assistante/home-assistante.component.ts
  2. 111
      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 { Observable, Subscription } from 'rxjs';
import { ServiceCollaborateur } from "../../service";
import { CollaborateurModel } from "../../modeles/modele-collaborateur";
@Component({
selector : 'home-assistante',
@ -10,39 +7,17 @@ import { CollaborateurModel } from "../../modeles/modele-collaborateur";
})
export class HomeAssistanteComponent implements OnInit {
private collabListSubscription : Subscription;
private collab1Subscription : Subscription;
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));
constructor() {
}
test(collaborateurs) {
for(let collaborateur of collaborateurs) {
console.log(collaborateur);
}
}
test2(collaborateur) {
console.log(collaborateur);
}
ngOnInit() {
}
ngOnDestroy() {
if(this.collabListSubscription != null) {
this.collabListSubscription.unsubscribe();
}
}
}

@ -1,6 +1,13 @@
import { Component, OnInit } from '@angular/core';
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';
@ -18,12 +25,112 @@ import { Role } from '../utils/roles';
export class HomeComponent implements OnInit {
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() {
}
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;
nom? : string;
prenom? : string;
adresse? : string;
agence? : string;
mail? : string;
agence? : string;
dateEmbauche? : Date;
fonction? : string;
};

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

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

@ -2,6 +2,10 @@ import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { KeycloakService } from 'keycloak-angular';
import { urlCollaborateur } from "../utils/path-values-collaborateurs";
import { CollaborateurModel } from "../modeles/modele-collaborateur";
@ -9,15 +13,19 @@ import { CollaborateurModel } from "../modeles/modele-collaborateur";
providedIn : 'root'
})
export class ServiceCollaborateur {
constructor(private http: HttpClient) {
constructor(private http: HttpClient, private keycloakService : KeycloakService) {
}
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> {
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 { Observable } from 'rxjs';
import { KeycloakService } from 'keycloak-angular';
import { urlsEP } from "../utils/path-values-ep";
import { EpModel, RDVEntretienModel } from "../modeles/modele-ep";
@ -9,51 +11,73 @@ import { EpModel, RDVEntretienModel } from "../modeles/modele-ep";
providedIn : 'root'
})
export class ServiceEP {
constructor(private http: HttpClient) {
}
constructor(private http: HttpClient, private keycloakService : KeycloakService) {}
listeProchainsEPReferent(id) : Observable<EpModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
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[]> {
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[]> {
let token = this.keycloakService.getKeycloakInstance().token;
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[]> {
let token = this.keycloakService.getKeycloakInstance().token;
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> {
let token = this.keycloakService.getKeycloakInstance().token;
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) {
let params = { action : action };
return this.http.post<EpModel>(urlsEP.envoieEP, ep, {params});
let token = this.keycloakService.getKeycloakInstance().token;
let params = { action };
const headers = {
Authorization: "Bearer "+token,
ContentType: "application/json"
};
return this.http.put<EpModel>(urlsEP.envoieEP, ep, {params, headers});
}
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) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idEp : id };
return this.http.get(urlsEP.rappelSignature, {params});
return this.http.post(urlsEP.rappelSignature, null, {params, headers});
}
demandeEPI(id) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
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 { Observable } from "rxjs";
import { KeycloakService } from 'keycloak-angular';
import {FormationModel, DemandeFormationModel, EvaluationFormationModel, ThemeModel } from "../modeles/modele-formation";
import { urlsFormation } from "../utils/path-values-formations";
@ -9,53 +11,79 @@ import { urlsFormation } from "../utils/path-values-formations";
providedIn : 'root'
})
export class ServiceFormation {
constructor(private http: HttpClient) {
}
constructor(private http: HttpClient, private keycloakService : KeycloakService) {}
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[]> {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
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> {
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> {
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) {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idFormation : id };
return this.http.delete(urlsFormation.urlFormation);
return this.http.delete(urlsFormation.urlFormation, {headers, params});
}
evaluationsFormation(id) : Observable<EvaluationFormationModel[]> {
let token = this.keycloakService.getKeycloakInstance().token;
const headers = { Authorization: "Bearer "+token };
let params = { idFormation : id };
return this.http.get<EvaluationFormationModel[]>(urlsFormation.evaluationsFormation);
return this.http.get<EvaluationFormationModel[]>(urlsFormation.evaluationsFormation, {headers, params});
}
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[]> {
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) {
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[]> {
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 = {
url : "http://localhost:3000"
//url : "http:localhost:3000/api"
url : "http://localhost:3000/api"
}
export const environment = {

Loading…
Cancel
Save