diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index 79abef7df3942504935f52044c66b875f6ba384c..ac04735881d4d6f03b4b2c35ef12a7b7ce3c52e2 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -12,9 +12,7 @@ import { AuthService } from '../../services/auth.service'; export class ProfileService { private readonly baseUrl = 'api/users'; private currentProfile: User = null; - constructor(private http: HttpClient, private authService: AuthService) { - this.getProfile(); - } + constructor(private http: HttpClient, private authService: AuthService) {} public async getProfile(): Promise<User> { // Get profil by API only on first time diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index 5b928a6a5bf877e042e7c336774891d5c0416ce7..f767540dcf7e19398809830daf1d5955ebeeb11e 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -31,8 +31,8 @@ export class StructureService { return this.http.put(`${this.baseUrl}/${id}`, structure).pipe(map((item: Structure) => new Structure(item))); } - public isClaimed(id: string): Observable<any> { - return this.http.get(`${this.baseUrl}/${id}/isClaimed`); + public isClaimed(id: string, profile: User): Observable<boolean> { + return this.http.post<boolean>(`${this.baseUrl}/${id}/isClaimed`, profile); } public claimStructureWithAccount(id: string, user: User): Observable<string[]> { diff --git a/src/app/structure-list/components/structure-details/structure-details.component.ts b/src/app/structure-list/components/structure-details/structure-details.component.ts index a19579210b475156c5d4093e5e3f4afe74ba992c..71619679ee561c260bbb728c11b6b4191946cddb 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.ts +++ b/src/app/structure-list/components/structure-details/structure-details.component.ts @@ -37,7 +37,7 @@ export class StructureDetailsComponent implements OnInit { public isClaimed: boolean = null; public isLoading: boolean = false; public isEditMode: boolean = false; - public currentProfile: User; + public currentProfile: User = null; constructor( route: ActivatedRoute, @@ -56,37 +56,33 @@ export class StructureDetailsComponent implements OnInit { }); } - ngOnInit(): void { + async ngOnInit(): Promise<void> { this.isLoading = true; if (this.authService.isLoggedIn()) { - this.profileService.getProfile().then((p: User) => { - this.currentProfile = p; - }); + this.currentProfile = await this.profileService.getProfile(); } + this.isClaimed = await this.structureService.isClaimed(this.structure._id, this.currentProfile).toPromise(); // GetTclStopPoints this.getTclStopPoints(); - this.structureService.isClaimed(this.structure._id).subscribe((boolean) => { - this.isClaimed = boolean; - this.searchService.getCategoriesTraining().subscribe((referentiels) => { - referentiels.forEach((referentiel) => { - if (referentiel.isBaseSkills()) { - this.baseSkillssReferentiel = referentiel; - } else if (referentiel.isRigthtsAccess()) { - this.accessRightsReferentiel = referentiel; - } - }); - this.setServiceCategories(); - if (this.printMode) { - this.printService.onDataReady(); + this.searchService.getCategoriesTraining().subscribe((referentiels) => { + referentiels.forEach((referentiel) => { + if (referentiel.isBaseSkills()) { + this.baseSkillssReferentiel = referentiel; + } else if (referentiel.isRigthtsAccess()) { + this.accessRightsReferentiel = referentiel; } - this.isLoading = false; }); - const index = this.structure.proceduresAccompaniment.indexOf('autres'); - if (index > -1) { - this.structure.proceduresAccompaniment.splice(index, 1); - this.isOtherSection = true; + this.setServiceCategories(); + if (this.printMode) { + this.printService.onDataReady(); } + this.isLoading = false; }); + const index = this.structure.proceduresAccompaniment.indexOf('autres'); + if (index > -1) { + this.structure.proceduresAccompaniment.splice(index, 1); + this.isOtherSection = true; + } } public getEquipmentsLabel(equipment: Equipment): string {