Created
November 26, 2018 18:08
-
-
Save AyoubEd-zz/9856349b3b5e10d19f8762333befe647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Comment } from './types'; | |
import { ICommentStorage, CommentStorage } from './comment.storage'; | |
export interface ICommentService { | |
getComments(itemId: string): Promise<[Comment]>; | |
addComments(itemId: string, userId: string, content: string): Promise<[Comment]>; | |
editComments(itemId: string, msgId: number, userId: string, content: string): Promise<[Comment]>; | |
deleteComments(itemId: string, msgId: number, userId: string): Promise<[Comment]>; | |
} | |
export class CommentService implements ICommentService { | |
commentStore: ICommentStorage; | |
constructor(store?: ICommentStorage) { | |
if (store) { | |
this.commentStore = store | |
} else { | |
this.commentStore = new CommentStorage(); | |
} | |
} | |
getComments(itemId): Promise<[Comment]> { | |
return this.commentStore.get(itemId); | |
} | |
addComments(itemId, userId, content): Promise<[Comment]> { | |
return this.commentStore.add(itemId, userId, content); | |
} | |
editComments(itemId, msgId, userId, content): Promise<[Comment]> { | |
return this.commentStore.edit(itemId, msgId, userId, content); | |
} | |
deleteComments(itemId, msgId, userId): Promise<[Comment]> { | |
return this.commentStore.delete(itemId, msgId, userId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment