diff --git a/src/app/features/model-details/model-details.component.ts b/src/app/features/model-details/model-details.component.ts index 262ad0587c77c9a422516255a4eb5bfba0d94a82..23f4d67d6050775b983829e2263834743abf364c 100644 --- a/src/app/features/model-details/model-details.component.ts +++ b/src/app/features/model-details/model-details.component.ts @@ -58,12 +58,12 @@ interface SolutionData { revisionId: string; solution: PublicSolutionDetailsModel; catalogs: Catalog[]; - picture: any; - averageRatings: AverageRatings; - allRatings: AllUserRating[]; + picture?: any; + averageRatings?: AverageRatings; + allRatings?: AllUserRating[]; comments: any; authors: AuthorPublisherModel[]; - relatedSolutions: PublicSolution[]; + relatedSolutions?: PublicSolution[]; } @Component({ @@ -163,6 +163,9 @@ export class ModelDetailsComponent implements OnInit { .pipe(map((details) => !!details?.userId)); this.data$ = this.activatedRoute.params.pipe( + tap((params) => { + console.log({ params }); + }), map((params) => ({ solutionId: params['solutionId'] as string, revisionId: params['revisionId'] as string, @@ -178,22 +181,26 @@ export class ModelDetailsComponent implements OnInit { solution: of(solution), catalogs: this.publicSolutionsService.getCatalogsOfSolution(solutionId), - picture: - this.publicSolutionsService.getPictureOfSolution(solutionId), - averageRatings: - this.publicSolutionsService.getAverageRatings(solutionId), - allRatings: - this.publicSolutionsService.getAllRatings(solutionId), - comments: this.publicSolutionsService.getComment( - solutionId, - revisionId, - ), - authors: this.publicSolutionsService.getModelAuthors( - solutionId, - revisionId, - ), - relatedSolutions: - this.publicSolutionsService.relatedSolutions(solution), + picture: this.publicSolutionsService + .getPictureOfSolution(solutionId) + .pipe(catchError(() => of(null))), + averageRatings: this.publicSolutionsService + .getAverageRatings(solutionId) + .pipe(catchError(() => of({} as AverageRatings))), + allRatings: this.publicSolutionsService + .getAllRatings(solutionId) + .pipe(catchError(() => of([]))), + comments: this.publicSolutionsService + .getComment(solutionId, revisionId) + .pipe( + catchError(() => of({ response_body: { content: [] } })), + ), + authors: this.publicSolutionsService + .getModelAuthors(solutionId, revisionId) + .pipe(catchError(() => of([]))), + relatedSolutions: this.publicSolutionsService + .relatedSolutions(solution) + .pipe(catchError(() => of([]))), }), ), tap((data) => { @@ -424,7 +431,9 @@ export class ModelDetailsComponent implements OnInit { private processSideEffects(data: SolutionData): void { this.revisionsList = this.getRevisionsList(data.solution); - this.selectedDefaultRevision = this.revisionsList[0]; + this.selectedDefaultRevision = this.revisionsList.filter( + (rv) => rv.revisionId === this.revisionId, + )[0]; this.setRevisionInService(this.selectedDefaultRevision); if (data.catalogs.length > 0) { @@ -433,10 +442,10 @@ export class ModelDetailsComponent implements OnInit { } this.setVersionIdInService(); this.createImageFromBlob(data.picture); - this.updateStarWidth(data.averageRatings); - this.calculateRatings(data.allRatings); + this.updateStarWidth(data.averageRatings || ({} as AverageRatings)); + this.calculateRatings(data.allRatings || []); this.setAuthorListInService(data.authors); - this.removeCurrentSolution(data.relatedSolutions, data.solution); + this.removeCurrentSolution(data.relatedSolutions || [], data.solution); } triggerDeployment(menuEntry: {