From 86c7bee61e69be13fd130c03280825a5149452f8 Mon Sep 17 00:00:00 2001 From: Lukas Haase <lukas.haase@mni.thm.de> Date: Wed, 18 Aug 2021 12:39:21 +0200 Subject: [PATCH] create role function in comment service, add createdBy to comment.ts, test for moderatorids and createdbylecturer --- .../comment-list/comment-list.component.ts | 4 +-- .../shared/comment/comment.component.ts | 1 + src/app/models/comment.ts | 5 +++- src/app/services/http/comment.service.ts | 25 +++++++++++-------- 4 files changed, 22 insertions(+), 13 deletions(-) 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 87dbbd3fd..f2349930f 100644 --- a/src/app/components/shared/comment-list/comment-list.component.ts +++ b/src/app/components/shared/comment-list/comment-list.component.ts @@ -423,9 +423,9 @@ export class CommentListComponent implements OnInit, OnDestroy { case this.owner: return c.creatorId === this.user.id; case this.moderator: - return c.creatorId === this.user.id && (this.user.role === 2 || this.user.role === 1); + return this.moderatorIds.includes(c.creatorId); case this.lecturer: - return c.creatorId === this.user.id && this.user.role === 3; + return c.createdFromLecturer; } }); this.hideCommentsList = true; diff --git a/src/app/components/shared/comment/comment.component.ts b/src/app/components/shared/comment/comment.component.ts index 328d4675c..76f7e91fa 100644 --- a/src/app/components/shared/comment/comment.component.ts +++ b/src/app/components/shared/comment/comment.component.ts @@ -64,6 +64,7 @@ export class CommentComponent implements OnInit, AfterViewInit { isExpandable = false; selectedKeyword = ''; filterProfanityForModerators = false; + createdBy; constructor(protected authenticationService: AuthenticationService, private route: ActivatedRoute, diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index 42a2fb55f..18b77b83d 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -26,6 +26,7 @@ export class Comment { upvotes: number; downvotes: number; language: Language; + createdBy; constructor(roomId: string = '', creatorId: string = '', @@ -46,7 +47,8 @@ export class Comment { keywordsFromSpacy: SpacyKeyword[] = [], upvotes = 0, downvotes = 0, - language = Language.auto) { + language = Language.auto, + createdBy?: any) { this.id = ''; this.roomId = roomId; this.creatorId = creatorId; @@ -69,6 +71,7 @@ export class Comment { this.upvotes = upvotes; this.downvotes = downvotes; this.language = language; + this.createdBy = createdBy; } static mapModelToLanguage(model: Model): Language { diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index b92ecdd14..266fdcf81 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -105,7 +105,7 @@ export class CommentService extends BaseHttpService { getAckComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId, ack: true }, + properties: { roomId, ack: true }, externalFilters: {} }, httpOptions).pipe( map(commentList => commentList.map(comment => this.parseComment(comment))), @@ -117,12 +117,10 @@ export class CommentService extends BaseHttpService { getRejectedComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId, ack: false }, + properties: { roomId, ack: false }, externalFilters: {} }, httpOptions).pipe( - map(commentList => { - return commentList.map(comment => this.parseComment(comment)); - }), + map(commentList => commentList.map(comment => this.parseComment(comment))), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -131,12 +129,10 @@ export class CommentService extends BaseHttpService { getComments(roomId: string): Observable<Comment[]> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find; return this.http.post<Comment[]>(connectionUrl, { - properties: { roomId: roomId }, + properties: { roomId }, externalFilters: {} }, httpOptions).pipe( - map(commentList => { - return commentList.map(comment => this.parseComment(comment)); - }), + map(commentList => commentList.map(comment => this.parseComment(comment))), tap(_ => ''), catchError(this.handleError<Comment[]>('getComments', [])) ); @@ -175,6 +171,14 @@ export class CommentService extends BaseHttpService { ); } + role(comment: Comment) { + const connectionUrl = this.apiUrl.base + this.apiUrl.comment + '/' + comment.id + '/role'; + return this.http.patch(connectionUrl, httpOptions).pipe( + tap(_ => ''), + catchError(this.handleError<any>('roleComment')) + ); + } + deleteCommentsByRoomId(roomId: string): Observable<Comment> { const connectionUrl = `${this.apiUrl.base + this.apiUrl.comment}/byRoom?roomId=${roomId}`; return this.http.delete<Comment>(connectionUrl, httpOptions).pipe( @@ -186,7 +190,7 @@ export class CommentService extends BaseHttpService { countByRoomId(roomId: string, ack: boolean): Observable<number> { const connectionUrl = this.apiUrl.base + this.apiUrl.comment + this.apiUrl.find + this.apiUrl.count; return this.http.post<number>(connectionUrl, { - properties: { roomId: roomId, ack: ack }, + properties: { roomId, ack }, externalFilters: {} }, httpOptions).pipe( tap(_ => ''), @@ -231,6 +235,7 @@ export class CommentService extends BaseHttpService { comment.keywordsFromQuestioner = comment.keywordsFromQuestioner ? JSON.parse(comment.keywordsFromQuestioner as unknown as string) : null; comment.keywordsFromSpacy = comment.keywordsFromSpacy ? JSON.parse(comment.keywordsFromSpacy as unknown as string) : null; + console.log(comment); return comment; } -- GitLab