{"action":"created","issue":{"url":"https://api.github.com/repos/postgres-plugin/challenges/issues/9","repository_url":"https://api.github.com/repos/postgres-plugin/challenges","labels_url":"https://api.github.com/repos/postgres-plugin/challenges/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/postgres-plugin/challenges/issues/9/comments","events_url":"https://api.github.com/repos/postgres-plugin/challenges/issues/9/events","html_url":"https://github.com/postgres-plugin/challenges/issues/9","id":190945926,"number":9,"title":"GetChallengesByTag (browse/filter by tag)","user":{"login":"JMurphyWeb","id":12638261,"avatar_url":"https://avatars.githubusercontent.com/u/12638261?v=3","gravatar_id":"","url":"https://api.github.com/users/JMurphyWeb","html_url":"https://github.com/JMurphyWeb","followers_url":"https://api.github.com/users/JMurphyWeb/followers","following_url":"https://api.github.com/users/JMurphyWeb/following{/other_user}","gists_url":"https://api.github.com/users/JMurphyWeb/gists{/gist_id}","starred_url":"https://api.github.com/users/JMurphyWeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JMurphyWeb/subscriptions","organizations_url":"https://api.github.com/users/JMurphyWeb/orgs","repos_url":"https://api.github.com/users/JMurphyWeb/repos","events_url":"https://api.github.com/users/JMurphyWeb/events{/privacy}","received_events_url":"https://api.github.com/users/JMurphyWeb/received_events","type":"User","site_admin":false},"labels":[{"id":481377606,"url":"https://api.github.com/repos/postgres-plugin/challenges/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-22T09:22:31Z","updated_at":"2016-11-23T12:16:26Z","closed_at":null,"body":"Query should:\r\n- Return all challenges which meet a certain tag id\r\n- Return all tag-names for each challenge in the list to be displayed in the browse view\r\n- Return the tag name that we are filtering by for us to display at the top of the browse view\r\n- Possibly add 'Shared By' column and the name of the org that has created the challenge as requested in an issue on ce100 (i cannot find right now)\r\nFunction should:\r\n- Shape all the data into a format that is accepted by handlebars\r\n\r\nFirst iteration of the query function has been written\r\n\r\n```js\r\n'use strict';\r\n\r\n\r\n/*\r\n* We pass getByTag a table that we want get ('challenges') and a tag id\r\n* that we want to filter by. This function should return all of the challenges\r\n* that meet that contain that tag.\r\n*/\r\n\r\n\r\nmodule.exports = function getChalsByTag (tagId) {\r\n  return `SELECT\r\n      tags.id, tags.name,\r\n      challenges.id, challenges.date, challenges.title, challenges.description,\r\n      challenges.creator_id, challenges.creator_id\r\n    from tags\r\n    JOIN\r\n      tags_challenges ON tags.id = ` + tagId + ` AND tags_challenges.tags_id = tags.id\r\n    JOIN\r\n    challenges ON tags_challenges.challenges_id = challenges.id;`\r\n}\r\n```\r\n\r\nAnd inside the plugin: \r\n\r\n```js\r\n\r\n\r\n      request.pg.challenges.getChalsByTag = function (id, cb) {\r\n        return query(queries.getChalsByTag(id), pool, cb);\r\n      };\r\n\r\n```\r\n\r\nroute for testing:\r\n```js\r\n, {\r\n      method: 'GET',\r\n      path: '/getChalsByTag',\r\n      handler: function (request, reply) {\r\n        request.pg.tags.getChalsByTag(request.query.tags, function (error, challenges) {\r\n          Hoek.assert(!error, error);\r\n\r\n          return reply(challenges);\r\n        });\r\n      }\r\n    }\r\n\r\n```\r\n\r\nTest file:\r\n```js\r\n'use strict';\r\n\r\nvar test = require('tape');\r\nvar Hoek = require('hoek');\r\nvar config = require('../config/load-config.js');\r\nvar init = require('../example/server.js');\r\nvar createChallenges = require('./helpers/create-challenges.js');\r\nvar tagsData = require('./helpers/fixtures/tags.json');\r\nvar categoriesData = require('./helpers/fixtures/categories.json');\r\n\r\ntest('get all challenges with tag id 2 attached using getByTag function', function (t) { //eslint-disable-line\r\n  config.tagsData = tagsData;\r\n  config.categoriesData = categoriesData;\r\n\r\n  init(config, function (error, server, pool) {\r\n    if (error) {\r\n      return t.fail(error);\r\n    }\r\n\r\n    return createChallenges(pool, function (createChallengeError) {\r\n      var options = { url: '/getByTag?tags=2' };\r\n\r\n      Hoek.assert(!createChallengeError, 'create challenges error');\r\n\r\n      return server.inject(options, function (response) {\r\n        t.equal(response.result.length, 2, '2 Challenges are returned');\r\n\r\n        return pool.end(function () { // eslint-disable-line\r\n          server.stop(t.end);\r\n        });\r\n      });\r\n    });\r\n  });\r\n});\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/postgres-plugin/challenges/issues/comments/262498475","html_url":"https://github.com/postgres-plugin/challenges/issues/9#issuecomment-262498475","issue_url":"https://api.github.com/repos/postgres-plugin/challenges/issues/9","id":262498475,"user":{"login":"JMurphyWeb","id":12638261,"avatar_url":"https://avatars.githubusercontent.com/u/12638261?v=3","gravatar_id":"","url":"https://api.github.com/users/JMurphyWeb","html_url":"https://github.com/JMurphyWeb","followers_url":"https://api.github.com/users/JMurphyWeb/followers","following_url":"https://api.github.com/users/JMurphyWeb/following{/other_user}","gists_url":"https://api.github.com/users/JMurphyWeb/gists{/gist_id}","starred_url":"https://api.github.com/users/JMurphyWeb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JMurphyWeb/subscriptions","organizations_url":"https://api.github.com/users/JMurphyWeb/orgs","repos_url":"https://api.github.com/users/JMurphyWeb/repos","events_url":"https://api.github.com/users/JMurphyWeb/events{/privacy}","received_events_url":"https://api.github.com/users/JMurphyWeb/received_events","type":"User","site_admin":false},"created_at":"2016-11-23T12:16:26Z","updated_at":"2016-11-23T12:16:26Z","body":"My query returns the same results for when i make the category that tag 68 sits in (with `categoreis.id: 6`)."}}
{"actor":{"display_login":"JMurphyWeb"}}