import BaseDataSource from '../shared/base.datasource' ; import { ID } from '../shared/shared.types' ; import { ReactionType } from '../generated/graphql' ; class ReactionAPI extends BaseDataSource { async addReaction ( reactableId , type ) { const { db } = this . context ; const result = await db . reaction . addViewerReaction ( { reactableId , type , } ) ; return result ; } async removeReaction ( reactableId ) { const { db } = this . context ; const result = await db . reaction . removeViewerReaction ( reactableId ) ; return result ; } async findOneViewerReaction ( reactableId ) { const { db , viewer } = this . context ; if ( ! viewer ) { return null ; } const reaction = await db . reaction . findOneUserReaction ( viewer . id , reactableId ) ; return reaction ?. type ; } async countReactionsByReactableId ( reactableId ) { const { db } = this . context ; const reactionsCount = await db . reaction . countByReactableId ( reactableId ) ; return reactionsCount ; } } export default ReactionAPI ;