Skip to content

Instantly share code, notes, and snippets.

@AyoubEd-zz
Created November 26, 2018 18:08
Show Gist options
  • Save AyoubEd-zz/9856349b3b5e10d19f8762333befe647 to your computer and use it in GitHub Desktop.
Save AyoubEd-zz/9856349b3b5e10d19f8762333befe647 to your computer and use it in GitHub Desktop.
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