diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index e28d78f8f4bacf463e01f4bfdd1ee32a232110fe..d61ba987b088fc4bcabc98c0434425f82c503e3b 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, email: string): 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 59c5011ba4fb647b4d5bce1a89aae023920ddc22..bb2505864b4b87497ca525aee952aea529b4041a 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 getEquipmentsIcon(equipment: Equipment): string {