Skip to content
Snippets Groups Projects
Commit aae0fec7 authored by Lukas Mauß's avatar Lukas Mauß
Browse files

Fix comment creation successfully

parent 0f316ba7
Branches
Tags
No related merge requests found
......@@ -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.`);
});
}
......
......@@ -6,5 +6,5 @@ export class Comment {
subject: string;
body: string;
read: boolean;
creationTimestamp: Date;
creationTimestamp: number;
}
......@@ -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'))
);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment