How to use the actionhero.api.blog function in actionhero

To help you get started, we’ve selected a few actionhero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
await redis.del(commentKey)
    }

    api.blog.commentAdd = async (userName, title, commenterName, comment) => {
      const key = api.blog.buildCommentKey(userName, title)
      const commentId = api.blog.buildCommentId(commenterName)
      const data = {
        comment,
        commenterName,
        createdAt: new Date().getTime(),
        commentId: commentId
      }
      await redis.hset(key, commentId, JSON.stringify(data))
    }

    api.blog.commentsView = async (userName, title) => {
      const key = api.blog.buildCommentKey(userName, title)
      const data = await redis.hgetall(key)
      const comments = Object.keys(data).map((key) => {
        const comment = data[key]
        return JSON.parse(comment)
      })
      return comments
    }

    api.blog.commentDelete = async (userName, title, commentId) => {
      const key = api.blog.buildCommentKey(userName, title)
      await redis.hdel(key, commentId)
    }

    api.blog.buildTitleKey = (userName, title) => {
      // "posts:evan:my first post"
github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
api.blog.commentDelete = async (userName, title, commentId) => {
      const key = api.blog.buildCommentKey(userName, title)
      await redis.hdel(key, commentId)
    }

    api.blog.buildTitleKey = (userName, title) => {
      // "posts:evan:my first post"
      return api.blog.postPrefix + api.blog.separator + userName + api.blog.separator + title
    }

    api.blog.buildCommentKey = (userName, title) => {
      // "comments:evan:my first post"
      return api.blog.commentPrefix + api.blog.separator + userName + api.blog.separator + title
    }

    api.blog.buildCommentId = (commenterName) => {
      return commenterName + new Date().getTime()
    }
  }
github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
return JSON.parse(comment)
      })
      return comments
    }

    api.blog.commentDelete = async (userName, title, commentId) => {
      const key = api.blog.buildCommentKey(userName, title)
      await redis.hdel(key, commentId)
    }

    api.blog.buildTitleKey = (userName, title) => {
      // "posts:evan:my first post"
      return api.blog.postPrefix + api.blog.separator + userName + api.blog.separator + title
    }

    api.blog.buildCommentKey = (userName, title) => {
      // "comments:evan:my first post"
      return api.blog.commentPrefix + api.blog.separator + userName + api.blog.separator + title
    }

    api.blog.buildCommentId = (commenterName) => {
      return commenterName + new Date().getTime()
    }
  }
github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
api.blog.buildTitleKey = (userName, title) => {
      // "posts:evan:my first post"
      return api.blog.postPrefix + api.blog.separator + userName + api.blog.separator + title
    }
github actionhero / actionhero-tutorial / initializers / blog.js View on Github external
async initialize () {
    const redis = api.redis.clients.client

    api.blog = {
      separator: ';',
      postPrefix: 'posts',
      commentPrefix: 'comments:'
    }

    api.blog.postAdd = async (userName, title, content) => {
      const key = api.blog.buildTitleKey(userName, title)
      const data = {
        content,
        title,
        userName,
        createdAt: new Date().getTime(),
        updatedAt: new Date().getTime()
      }
      await redis.hmset(key, data)
    }

    api.blog.postView = async (userName, title) => {
      const key = api.blog.buildTitleKey(userName, title)
      return redis.hgetall(key)
    }
github actionhero / actionhero-tutorial / actions / blog.js View on Github external
async run ({ response, params }) {
    response.post = await api.blog.postView(params.userName, params.title)
  }
}
github actionhero / actionhero-tutorial / initializers / users.js View on Github external
api.users.delete = async (userName, password) => {
      await redis.del(this.usersHash, userName)
      const titles = await api.blog.postsList(userName)
      for (const i in titles) {
        await api.blog.deletePost(userName, titles[i])
      }
    }
github actionhero / actionhero-tutorial / actions / blog.js View on Github external
async run ({ params }) {
    await api.blog.commentDelete(params.userName, params.title, params.commentId)
  }
}
github actionhero / actionhero-tutorial / actions / blog.js View on Github external
async run ({ params }) {
    await api.blog.commentAdd(params.userName, params.title, params.commenterName, params.comment)
  }
}
github actionhero / actionhero-tutorial / actions / blog.js View on Github external
async run ({ params }) {
    await api.blog.postDelete(params.userName, params.title)
  }
}