From aae0fec71c5b3c05bc2f5a6c78557f5c25f5a096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Thu, 5 Apr 2018 15:02:13 +0200 Subject: [PATCH] Fix comment creation successfully --- .../comment-create-page.component.ts | 19 ++++++++----------- src/app/models/comment.ts | 2 +- src/app/services/http/comment.service.ts | 5 ++++- 3 files changed, 13 insertions(+), 13 deletions(-) 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 0df47cf08..39a46689a 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 @@ -17,8 +17,9 @@ import { CommentListComponent } from '../../fragments/comment-list/comment-list. }) export class CommentCreatePageComponent implements OnInit { @ViewChild(CommentListComponent) child: CommentListComponent; - @Input() room: Room; + roomId: string; user: User; + private date = new Date(Date.now()); constructor( protected authenticationService: AuthenticationService, @@ -30,13 +31,7 @@ export class CommentCreatePageComponent implements OnInit { ngOnInit(): void { this.user = this.authenticationService.getUser(); - this.route.params.subscribe(params => { - this.getRoom(params['roomId']); - }); - } - - getRoom(id: string): void { - this.roomService.getRoom(id).subscribe(room => this.room = room); + this.roomId = this.route.snapshot.paramMap.get('roomId'); } send(subject: string, body: string): void { @@ -47,13 +42,15 @@ export class CommentCreatePageComponent implements OnInit { } this.commentService.addComment({ id: '', - roomId: this.room.id, + roomId: this.roomId, userId: this.user.id, subject: subject, body: body, - creationTimestamp: new Date(Date.now()) + creationTimestamp: this.date.getTime(), + read: false, + revision: '' } as Comment).subscribe(() => { - this.child.getComments(this.room.id); + this.child.getComments(this.roomId); this.notification.show(`Comment '${subject}' successfully created.`); }); } diff --git a/src/app/models/comment.ts b/src/app/models/comment.ts index ed636d119..aed78ce9a 100644 --- a/src/app/models/comment.ts +++ b/src/app/models/comment.ts @@ -6,5 +6,5 @@ export class Comment { subject: string; body: string; read: boolean; - creationTimestamp: Date; + creationTimestamp: number; } diff --git a/src/app/services/http/comment.service.ts b/src/app/services/http/comment.service.ts index 86e1d47cc..32f1f43ac 100644 --- a/src/app/services/http/comment.service.ts +++ b/src/app/services/http/comment.service.ts @@ -24,7 +24,10 @@ export class CommentService extends BaseHttpService { /** TODO: getComment().. **/ addComment(comment: Comment): Observable<Comment> { - return this.http.post<Comment>(this.apiUrl.base + this.apiUrl.comment + '/', comment, httpOptions).pipe( + return this.http.post<Comment>(this.apiUrl.base + this.apiUrl.comment + '/', + { roomId: comment.roomId, subject: comment.subject, body: comment.body, + read: comment.read, creationTimestamp: comment.creationTimestamp + }, httpOptions).pipe( tap (_ => ''), catchError(this.handleError<Comment>('addComment')) ); -- GitLab