{"action":"created","issue":{"url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/78","repository_url":"https://api.github.com/repos/feathersjs/feathers-hooks-common","labels_url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/78/labels{/name}","comments_url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/78/comments","events_url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/78/events","html_url":"https://github.com/feathersjs/feathers-hooks-common/issues/78","id":196318651,"number":78,"title":"Read service using a slug instead of just _id","user":{"login":"eddyystop","id":1553311,"avatar_url":"https://avatars.githubusercontent.com/u/1553311?v=3","gravatar_id":"","url":"https://api.github.com/users/eddyystop","html_url":"https://github.com/eddyystop","followers_url":"https://api.github.com/users/eddyystop/followers","following_url":"https://api.github.com/users/eddyystop/following{/other_user}","gists_url":"https://api.github.com/users/eddyystop/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyystop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyystop/subscriptions","organizations_url":"https://api.github.com/users/eddyystop/orgs","repos_url":"https://api.github.com/users/eddyystop/repos","events_url":"https://api.github.com/users/eddyystop/events{/privacy}","received_events_url":"https://api.github.com/users/eddyystop/received_events","type":"User","site_admin":false},"labels":[{"id":513020033,"url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/labels/investigate%20idea","name":"investigate idea","color":"e99695","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-12-19T02:26:57Z","updated_at":"2017-01-19T17:34:48Z","closed_at":"2017-01-19T17:34:48Z","body":"I still think it can be implemented with a fairly simple hook for all cases by setting hook.id:\r\n\r\nfunction slugId(name, idField = '_id') {\r\n  const methods = [ 'get', 'update', 'patch', 'remove' ];\r\n\r\n  return function(hook) {\r\n    if(methods.indexOf(hook.method) !== -1) {\r\n      const query = {\r\n        [name]: hook.id\r\n      };\r\n\r\n      return hook.service.find({\r\n        query,\r\n        paginate: false\r\n      }).then(result => {\r\n        if(result.length === 1) {\r\n          hook.id = result[0][idField];\r\n        }\r\n\r\n        return hook;\r\n      });\r\n    }\r\n  }\r\n}\r\nThis can then be initialized for all services with\r\n\r\napp.hooks({\r\n  before: slugId('slug')\r\n});"},"comment":{"url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/comments/273843398","html_url":"https://github.com/feathersjs/feathers-hooks-common/issues/78#issuecomment-273843398","issue_url":"https://api.github.com/repos/feathersjs/feathers-hooks-common/issues/78","id":273843398,"user":{"login":"eddyystop","id":1553311,"avatar_url":"https://avatars.githubusercontent.com/u/1553311?v=3","gravatar_id":"","url":"https://api.github.com/users/eddyystop","html_url":"https://github.com/eddyystop","followers_url":"https://api.github.com/users/eddyystop/followers","following_url":"https://api.github.com/users/eddyystop/following{/other_user}","gists_url":"https://api.github.com/users/eddyystop/gists{/gist_id}","starred_url":"https://api.github.com/users/eddyystop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddyystop/subscriptions","organizations_url":"https://api.github.com/users/eddyystop/orgs","repos_url":"https://api.github.com/users/eddyystop/repos","events_url":"https://api.github.com/users/eddyystop/events{/privacy}","received_events_url":"https://api.github.com/users/eddyystop/received_events","type":"User","site_admin":false},"created_at":"2017-01-19T17:34:48Z","updated_at":"2017-01-19T17:34:48Z","body":"https://github.com/feathersjs/feathers-hooks-common/pull/111\r\n\r\nThis feature is included in feathers-hooks-common v3."}}
{"actor":{"display_login":"eddyystop"}}