diff --git a/src/app/components/fragments/comment-list/comment-list.component.ts b/src/app/components/fragments/comment-list/comment-list.component.ts index ff2e3707ab4cd40a9af081f1f11b5277aff842f7..849302cff02d018b897301a5140815184f2dc2d0 100644 --- a/src/app/components/fragments/comment-list/comment-list.component.ts +++ b/src/app/components/fragments/comment-list/comment-list.component.ts @@ -20,6 +20,7 @@ export class CommentListComponent implements OnInit { user: User; comments: Comment[]; isLoading = true; + roomId: string; constructor(protected authenticationService: AuthenticationService, private route: ActivatedRoute, @@ -32,32 +33,16 @@ export class CommentListComponent implements OnInit { ngOnInit() { this.userRole = this.authenticationService.getRole(); this.user = this.authenticationService.getUser(); - this.route.params.subscribe(params => { - this.getRoom(params['roomId']); - }); - } - - getRoom(id: string): void { - this.roomService.getRoom(id).subscribe( - params => { - this.getComments(params['id']); - }); + this.roomId = this.route.snapshot.paramMap.get('roomId'); + this.getComments(); } - getComments(roomId: string): void { - if (this.userRole === UserRole.CREATOR) { - this.commentService.getComments(roomId) - .subscribe(comments => { - this.comments = comments; - this.isLoading = false; - }); - } else if (this.userRole === UserRole.PARTICIPANT) { - this.commentService.searchComments(roomId, this.user.id) + getComments(): void { + this.commentService.getComments(this.roomId) .subscribe(comments => { this.comments = comments; this.isLoading = false; }); - } } setRead(comment: Comment): void { diff --git a/src/app/components/pages/comment-create-page/comment-create-page.component.ts b/src/app/components/pages/comment-create-page/comment-create-page.component.ts index 39a46689a786be4e1db58a2f47e164ab088fd1cd..0d171e08b117beb9af47d5554726320ec34099b6 100644 --- a/src/app/components/pages/comment-create-page/comment-create-page.component.ts +++ b/src/app/components/pages/comment-create-page/comment-create-page.component.ts @@ -50,7 +50,7 @@ export class CommentCreatePageComponent implements OnInit { read: false, revision: '' } as Comment).subscribe(() => { - this.child.getComments(this.roomId); + this.child.getComments(); this.notification.show(`Comment '${subject}' successfully created.`); }); } diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index 7a4ce7ba2ea5a8ac4e7f47f51c1b94e75e559e7e..dc9ba3e65a444adc44a0dda60b8eabf1ca769041 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -47,10 +47,10 @@ export class CommentService extends BaseHttpService { } getComments(roomId: string): Observable<Comment[]> { - const url = `${this.apiUrl.base + this}/?roomId=${roomId}`; + const url = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(url, { - properties: {}, - externalFilters: { roomId: roomId } + properties: { roomId: roomId }, + externalFilters: {} }, httpOptions).pipe( tap (_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) @@ -66,7 +66,7 @@ export class CommentService extends BaseHttpService { } updateComment(comment: Comment): Observable<any> { - return this.http.put(this.apiUrl + this.apiUrl.comment + comment.id, comment, httpOptions).pipe( + return this.http.put(this.apiUrl + this.apiUrl.comment + '/' + comment.id, comment, httpOptions).pipe( tap(_ => ''), catchError(this.handleError<any>('updateComment')) );