wiki/server/graph/resolvers/comment.js
/**
     * Fetch list of comments for a page
     */
Fetch list of comments for a page
Fetch list of comments for a page
async list (obj, args, context) {
      const page = await WIKI.models.pages.query().select('id').findOne({ localeCode: args.locale, path: args.path })
      if (page) {
        if (WIKI.auth.checkAccess(context.req.user, ['read:comments'], args)) {
          const comments = await WIKI.models.comments.query().where('pageId', page.id).orderBy('createdAt')
          return comments.map(c => ({
            ...c,
            authorName: c.name,
            authorEmail: c.email,
            authorIP: c.ip
          }))
        } else {
          throw new WIKI.Error.CommentViewForbidden()
        }
      } else {
        return []
      }
    }
async list ( obj , args , context ) { const page = await WIKI . models . pages . query ( ) . select ( 'id' ) . findOne ( { localeCode : args . locale , path : args . path } ) if ( page ) { if ( WIKI . auth . checkAccess ( context . req . user , [ 'read:comments' ] , args ) ) { const comments = await WIKI . models . comments . query ( ) . where ( 'pageId' , page . id ) . orderBy ( 'createdAt' ) return comments . map ( c => ( { ... c , authorName : c . name , authorEmail : c . email , authorIP : c . ip } ) ) } else { throw new WIKI . Error . CommentViewForbidden ( ) } } else { return [ ] } }
Fetch list of comments for a page
Fetch list of comments for a page