Rename firebase folder to solve conflict
This commit is contained in:
71
app/firebaseClient/services/comments/CommentService.ts
Normal file
71
app/firebaseClient/services/comments/CommentService.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// - Import react components
|
||||
import { firebaseRef, firebaseAuth } from 'app/firebaseClient/'
|
||||
|
||||
import { SocialError } from 'domain/common'
|
||||
import { ICommentService } from 'services/comments'
|
||||
import { Comment } from 'domain/comments'
|
||||
|
||||
/**
|
||||
* Firbase comment service
|
||||
*
|
||||
* @export
|
||||
* @class CommentService
|
||||
* @implements {ICommentService}
|
||||
*/
|
||||
export class CommentService implements ICommentService {
|
||||
public addComment: (postId: string, comment: Comment)
|
||||
=> Promise<string> = (postId, comment) => {
|
||||
return new Promise<string>((resolve,reject) => {
|
||||
let commentRef: any = firebaseRef.child(`postComments/${postId}`).push(comment)
|
||||
commentRef.then(() => {
|
||||
resolve(commentRef.key)
|
||||
})
|
||||
.catch((error: any) => {
|
||||
reject(new SocialError(error.code,error.message))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public getComments: ()
|
||||
=> Promise<{ [postId: string]: { [commentId: string]: Comment } }> = () => {
|
||||
return new Promise<{ [postId: string]: { [commentId: string]: Comment }}>((resolve,reject) => {
|
||||
let commentsRef: any = firebaseRef.child(`postComments`)
|
||||
commentsRef.on('value', (snapshot: any) => {
|
||||
let comments: {[postId: string]: {[commentId: string]: Comment}} = snapshot!.val() || {}
|
||||
resolve(comments)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public updateComment: (userId: string, postId: string, comment: Comment)
|
||||
=> Promise<void> = (userId, postId, comment) => {
|
||||
return new Promise<void>((resolve,reject) => {
|
||||
|
||||
let updates: any = {}
|
||||
updates[`postComments/${postId}/${userId}`] = comment
|
||||
firebaseRef.update(updates)
|
||||
.then(() => {
|
||||
resolve()
|
||||
})
|
||||
.catch((error: any) => {
|
||||
reject(new SocialError(error.code,error.message))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public deleteComment: (commentId: string, postId: string)
|
||||
=> Promise<void> = (commentId, postId) => {
|
||||
return new Promise<void>((resolve,reject) => {
|
||||
|
||||
let updates: any = {}
|
||||
updates[`postComments/${postId}/${commentId}`] = null
|
||||
firebaseRef.update(updates)
|
||||
.then(() => {
|
||||
resolve()
|
||||
})
|
||||
.catch((error: any) => {
|
||||
reject(new SocialError(error.code,error.message))
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user