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 0df47cf0898d5c8a6ac416a20c15f6179f62b953..39a46689a786be4e1db58a2f47e164ab088fd1cd 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 ed636d119cf2032562b9c8ac0d958b6c24ece93d..aed78ce9a3d621aaf7524545b47ab305c579a924 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 86e1d47cc0015f8512347336241e9725dc3ae620..32f1f43ac5a6f40c2045e854b55e4d37ca4c69f8 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')) );