import { ARTICLE_ACCESS_TYPE , ARTICLE_STATE } from 'common/enums' ; import { correctHtml } from 'common/utils' ; import { ArticleToContentResolver } from 'definitions' ; const resolver = async ( { articleId , authorId , content } , _ , { viewer , dataSources : { articleService , paymentService } , knex } ) => { const article = await articleService . dataloader . load ( articleId ) ; const isActive = article . state === ARTICLE_STATE . active ; const isAdmin = viewer . hasRole ( 'admin' ) ; const isAuthor = authorId === viewer . id ; if ( isAdmin || isAuthor ) { return correctHtml ( content ) ; } if ( ! isActive ) { return '' ; } const articleCircle = await articleService . findArticleCircle ( articleId ) ; if ( ! articleCircle ) { return correctHtml ( content ) ; } const isPublic = articleCircle . access === ARTICLE_ACCESS_TYPE . public ; if ( isPublic ) { return correctHtml ( content ) ; } if ( ! viewer . id ) { return '' ; } const isCircleMember = await paymentService . isCircleMember ( { userId : viewer . id , circleId : articleCircle . circleId , } ) ; if ( ! isCircleMember ) { return '' ; } return correctHtml ( content ) ; } ; export default resolver ;