From 3df3d139dd9da16d82eb2a1a431f11051006b34a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de>
Date: Fri, 10 May 2019 17:06:23 +0200
Subject: [PATCH] Add deleteComment function

---
 .../shared/comment-list/comment-list.component.html       | 3 +++
 .../shared/comment-list/comment-list.component.ts         | 4 ++++
 src/app/services/http/comment.service.ts                  | 8 ++++++++
 3 files changed, 15 insertions(+)

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 67389651d..886f34baf 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 96ba33332..edbaadb4c 100644
--- a/src/app/components/shared/comment-list/comment-list.component.ts
+++ b/src/app/components/shared/comment-list/comment-list.component.ts
@@ -200,4 +200,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 c3179ad69..df643a7db 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'))
+    );
+  }
 }
-- 
GitLab