diff --git a/src/app/components/shared/comment-list/comment-list.component.html b/src/app/components/shared/comment-list/comment-list.component.html index 67389651dd653103118019fbaf8963f31a365c7e..886f34baf99903c51dea2c4c29dfa201a309b555 100644 --- a/src/app/components/shared/comment-list/comment-list.component.html +++ b/src/app/components/shared/comment-list/comment-list.component.html @@ -49,6 +49,9 @@ <button mat-icon-button (focus)="hideCommentsList=false" (click)="sortTimeStamp()"> <mat-icon color="primary">remove</mat-icon> </button> + <button mat-icon-button *ngIf="userRole === 1" (focus)="hideCommentsList=false" (click)="deleteComments()"> + <mat-icon color="primary">delete</mat-icon> + </button> </div> </mat-menu> </div> diff --git a/src/app/components/shared/comment-list/comment-list.component.ts b/src/app/components/shared/comment-list/comment-list.component.ts index f3cc9319966c7c9d9f4074882a678bde6f26076e..8914b6d9362814552b4f6190c2937fa3f311eeb5 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -140,6 +140,13 @@ export class CommentListComponent implements OnInit { } } break; + case 'CommentDeleted': + for (let i = 0; i < this.comments.length; i++) { + this.comments = this.comments.filter(function (el) { + return el.id !== payload.id; + }); + } + break; } } @@ -200,4 +207,8 @@ export class CommentListComponent implements OnInit { return +dateB - +dateA; }); } + + deleteComments(): void { + this.commentService.deleteCommentsByRoomId(this.roomId).subscribe(); + } } diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index c3179ad69aad8f1c8811b5bdd8254d3294e47f31..df643a7db61f9f15b3497c94ff7bcc1ee4820c68 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -66,4 +66,12 @@ export class CommentService extends BaseHttpService { catchError(this.handleError<any>('updateComment')) ); } + + deleteCommentsByRoomId(roomId: string): Observable<Comment> { + const connectionUrl = `${this.apiUrl.base + this.apiUrl.comment}/byRoom?roomId=${roomId}`; + return this.http.delete<Comment>(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<Comment>('deleteComment')) + ); + } }