{"action":"created","comment":{"url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/comments/74362918","id":74362918,"diff_hunk":"@@ -1,3 +1,69 @@\n+# Media Suite Emberjs Style Guide\n+\n+## Prototype over static functions in model Custom Routes\n+                                 \n+* We should prefer using prototype model methods over static methods when tying to a custom end-point. Consider this static declaration route:\n+\n+```javascript\n+ Worksite.remoteMethod('startWork', {\n+   accepts: [\n+     {arg: 'id', type: 'number', required: true},\n+     {arg: 'data', type: 'object', http: {source: 'body'}}\n+   ],\n+   returns: {type: 'Worksite', root: true},\n+   http: {path: '/:id/start-work', verb: 'post', status: 200}\n+ })\n+```\n+\n+* By default this is a going to tie to a static method that would probably look a little like this:\n+\n+```javascript\n+ WorksiteSubmission.startWork = function (id, data, cb) {\n+   WorksiteSubmission.findById(id)\n+     .then(worksite => {\n+       if (!worksite) {\n+         const err = new Error('No worksite found')\n+         err.status = 404\n+         cb(err)\n+       }\n+       ...\n+```\n+\n+* In this example, we are required to look up the target model as one of the first operations of the method, and then check this was a valid model. \n+* All this can be handled for us if we use prototype methods, in the following structure:\n+\n+```javascript\n+ Worksite.remoteMethod('startWork', {\n+   accepts: [\n+     {arg: 'id', type: 'number', required: true},\n+     {arg: 'data', type: 'object', http: {source: 'body'}}\n+   ],\n+   isStatic: false,","path":"loopback-style-guide.md","position":41,"original_position":41,"commit_id":"629f63bfa201b09d759a7707085d7354fb5dc87f","original_commit_id":"629f63bfa201b09d759a7707085d7354fb5dc87f","user":{"login":"pnw","id":1459213,"avatar_url":"https://avatars.githubusercontent.com/u/1459213?v=3","gravatar_id":"","url":"https://api.github.com/users/pnw","html_url":"https://github.com/pnw","followers_url":"https://api.github.com/users/pnw/followers","following_url":"https://api.github.com/users/pnw/following{/other_user}","gists_url":"https://api.github.com/users/pnw/gists{/gist_id}","starred_url":"https://api.github.com/users/pnw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnw/subscriptions","organizations_url":"https://api.github.com/users/pnw/orgs","repos_url":"https://api.github.com/users/pnw/repos","events_url":"https://api.github.com/users/pnw/events{/privacy}","received_events_url":"https://api.github.com/users/pnw/received_events","type":"User","site_admin":false},"body":"\r\n1. `isStatic: false`\r\n2. the `/:id` portion of the path is removed like you said\r\n3. The method must be a prototype method `Worksite.prototype.startWork` not `Worksite.startWork`","created_at":"2016-08-11T02:37:10Z","updated_at":"2016-08-11T02:37:10Z","html_url":"https://github.com/mediasuitenz/tech-stack/pull/11#discussion_r74362918","pull_request_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11","_links":{"self":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/comments/74362918"},"html":{"href":"https://github.com/mediasuitenz/tech-stack/pull/11#discussion_r74362918"},"pull_request":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11"}}},"pull_request":{"url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11","id":80551604,"html_url":"https://github.com/mediasuitenz/tech-stack/pull/11","diff_url":"https://github.com/mediasuitenz/tech-stack/pull/11.diff","patch_url":"https://github.com/mediasuitenz/tech-stack/pull/11.patch","issue_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/11","number":11,"state":"open","locked":false,"title":"Recommendations about loopback prototype methods for custom end-points","user":{"login":"JonForest","id":4940106,"avatar_url":"https://avatars.githubusercontent.com/u/4940106?v=3","gravatar_id":"","url":"https://api.github.com/users/JonForest","html_url":"https://github.com/JonForest","followers_url":"https://api.github.com/users/JonForest/followers","following_url":"https://api.github.com/users/JonForest/following{/other_user}","gists_url":"https://api.github.com/users/JonForest/gists{/gist_id}","starred_url":"https://api.github.com/users/JonForest/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JonForest/subscriptions","organizations_url":"https://api.github.com/users/JonForest/orgs","repos_url":"https://api.github.com/users/JonForest/repos","events_url":"https://api.github.com/users/JonForest/events{/privacy}","received_events_url":"https://api.github.com/users/JonForest/received_events","type":"User","site_admin":false},"body":"I think we should favour prototype over static methods for Model endpoints where we are passing in an :id argument.\r\n\r\nThis PR is for discussion around that topic.","created_at":"2016-08-09T02:17:29Z","updated_at":"2016-08-11T02:37:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e0c057944a4535519c30b05d8d37d84a00ff4eaf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11/commits","review_comments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11/comments","review_comment_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/11/comments","statuses_url":"https://api.github.com/repos/mediasuitenz/tech-stack/statuses/629f63bfa201b09d759a7707085d7354fb5dc87f","head":{"label":"mediasuitenz:add/loopback-prototype-methods","ref":"add/loopback-prototype-methods","sha":"629f63bfa201b09d759a7707085d7354fb5dc87f","user":{"login":"mediasuitenz","id":4219296,"avatar_url":"https://avatars.githubusercontent.com/u/4219296?v=3","gravatar_id":"","url":"https://api.github.com/users/mediasuitenz","html_url":"https://github.com/mediasuitenz","followers_url":"https://api.github.com/users/mediasuitenz/followers","following_url":"https://api.github.com/users/mediasuitenz/following{/other_user}","gists_url":"https://api.github.com/users/mediasuitenz/gists{/gist_id}","starred_url":"https://api.github.com/users/mediasuitenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mediasuitenz/subscriptions","organizations_url":"https://api.github.com/users/mediasuitenz/orgs","repos_url":"https://api.github.com/users/mediasuitenz/repos","events_url":"https://api.github.com/users/mediasuitenz/events{/privacy}","received_events_url":"https://api.github.com/users/mediasuitenz/received_events","type":"Organization","site_admin":false},"repo":{"id":32112657,"name":"tech-stack","full_name":"mediasuitenz/tech-stack","owner":{"login":"mediasuitenz","id":4219296,"avatar_url":"https://avatars.githubusercontent.com/u/4219296?v=3","gravatar_id":"","url":"https://api.github.com/users/mediasuitenz","html_url":"https://github.com/mediasuitenz","followers_url":"https://api.github.com/users/mediasuitenz/followers","following_url":"https://api.github.com/users/mediasuitenz/following{/other_user}","gists_url":"https://api.github.com/users/mediasuitenz/gists{/gist_id}","starred_url":"https://api.github.com/users/mediasuitenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mediasuitenz/subscriptions","organizations_url":"https://api.github.com/users/mediasuitenz/orgs","repos_url":"https://api.github.com/users/mediasuitenz/repos","events_url":"https://api.github.com/users/mediasuitenz/events{/privacy}","received_events_url":"https://api.github.com/users/mediasuitenz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mediasuitenz/tech-stack","description":"Media Suite's evolving tech stack","fork":false,"url":"https://api.github.com/repos/mediasuitenz/tech-stack","forks_url":"https://api.github.com/repos/mediasuitenz/tech-stack/forks","keys_url":"https://api.github.com/repos/mediasuitenz/tech-stack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mediasuitenz/tech-stack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mediasuitenz/tech-stack/teams","hooks_url":"https://api.github.com/repos/mediasuitenz/tech-stack/hooks","issue_events_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/events{/number}","events_url":"https://api.github.com/repos/mediasuitenz/tech-stack/events","assignees_url":"https://api.github.com/repos/mediasuitenz/tech-stack/assignees{/user}","branches_url":"https://api.github.com/repos/mediasuitenz/tech-stack/branches{/branch}","tags_url":"https://api.github.com/repos/mediasuitenz/tech-stack/tags","blobs_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/refs{/sha}","trees_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mediasuitenz/tech-stack/statuses/{sha}","languages_url":"https://api.github.com/repos/mediasuitenz/tech-stack/languages","stargazers_url":"https://api.github.com/repos/mediasuitenz/tech-stack/stargazers","contributors_url":"https://api.github.com/repos/mediasuitenz/tech-stack/contributors","subscribers_url":"https://api.github.com/repos/mediasuitenz/tech-stack/subscribers","subscription_url":"https://api.github.com/repos/mediasuitenz/tech-stack/subscription","commits_url":"https://api.github.com/repos/mediasuitenz/tech-stack/commits{/sha}","git_commits_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/commits{/sha}","comments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/comments{/number}","issue_comment_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/comments{/number}","contents_url":"https://api.github.com/repos/mediasuitenz/tech-stack/contents/{+path}","compare_url":"https://api.github.com/repos/mediasuitenz/tech-stack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mediasuitenz/tech-stack/merges","archive_url":"https://api.github.com/repos/mediasuitenz/tech-stack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mediasuitenz/tech-stack/downloads","issues_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues{/number}","pulls_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls{/number}","milestones_url":"https://api.github.com/repos/mediasuitenz/tech-stack/milestones{/number}","notifications_url":"https://api.github.com/repos/mediasuitenz/tech-stack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mediasuitenz/tech-stack/labels{/name}","releases_url":"https://api.github.com/repos/mediasuitenz/tech-stack/releases{/id}","deployments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/deployments","created_at":"2015-03-13T01:04:12Z","updated_at":"2016-04-10T06:16:21Z","pushed_at":"2016-08-09T02:17:29Z","git_url":"git://github.com/mediasuitenz/tech-stack.git","ssh_url":"git@github.com:mediasuitenz/tech-stack.git","clone_url":"https://github.com/mediasuitenz/tech-stack.git","svn_url":"https://github.com/mediasuitenz/tech-stack","homepage":null,"size":28,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"mediasuitenz:master","ref":"master","sha":"8b8d8f880a1ed6b7323be78c8963fb1523fd15b0","user":{"login":"mediasuitenz","id":4219296,"avatar_url":"https://avatars.githubusercontent.com/u/4219296?v=3","gravatar_id":"","url":"https://api.github.com/users/mediasuitenz","html_url":"https://github.com/mediasuitenz","followers_url":"https://api.github.com/users/mediasuitenz/followers","following_url":"https://api.github.com/users/mediasuitenz/following{/other_user}","gists_url":"https://api.github.com/users/mediasuitenz/gists{/gist_id}","starred_url":"https://api.github.com/users/mediasuitenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mediasuitenz/subscriptions","organizations_url":"https://api.github.com/users/mediasuitenz/orgs","repos_url":"https://api.github.com/users/mediasuitenz/repos","events_url":"https://api.github.com/users/mediasuitenz/events{/privacy}","received_events_url":"https://api.github.com/users/mediasuitenz/received_events","type":"Organization","site_admin":false},"repo":{"id":32112657,"name":"tech-stack","full_name":"mediasuitenz/tech-stack","owner":{"login":"mediasuitenz","id":4219296,"avatar_url":"https://avatars.githubusercontent.com/u/4219296?v=3","gravatar_id":"","url":"https://api.github.com/users/mediasuitenz","html_url":"https://github.com/mediasuitenz","followers_url":"https://api.github.com/users/mediasuitenz/followers","following_url":"https://api.github.com/users/mediasuitenz/following{/other_user}","gists_url":"https://api.github.com/users/mediasuitenz/gists{/gist_id}","starred_url":"https://api.github.com/users/mediasuitenz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mediasuitenz/subscriptions","organizations_url":"https://api.github.com/users/mediasuitenz/orgs","repos_url":"https://api.github.com/users/mediasuitenz/repos","events_url":"https://api.github.com/users/mediasuitenz/events{/privacy}","received_events_url":"https://api.github.com/users/mediasuitenz/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mediasuitenz/tech-stack","description":"Media Suite's evolving tech stack","fork":false,"url":"https://api.github.com/repos/mediasuitenz/tech-stack","forks_url":"https://api.github.com/repos/mediasuitenz/tech-stack/forks","keys_url":"https://api.github.com/repos/mediasuitenz/tech-stack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mediasuitenz/tech-stack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mediasuitenz/tech-stack/teams","hooks_url":"https://api.github.com/repos/mediasuitenz/tech-stack/hooks","issue_events_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/events{/number}","events_url":"https://api.github.com/repos/mediasuitenz/tech-stack/events","assignees_url":"https://api.github.com/repos/mediasuitenz/tech-stack/assignees{/user}","branches_url":"https://api.github.com/repos/mediasuitenz/tech-stack/branches{/branch}","tags_url":"https://api.github.com/repos/mediasuitenz/tech-stack/tags","blobs_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/refs{/sha}","trees_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mediasuitenz/tech-stack/statuses/{sha}","languages_url":"https://api.github.com/repos/mediasuitenz/tech-stack/languages","stargazers_url":"https://api.github.com/repos/mediasuitenz/tech-stack/stargazers","contributors_url":"https://api.github.com/repos/mediasuitenz/tech-stack/contributors","subscribers_url":"https://api.github.com/repos/mediasuitenz/tech-stack/subscribers","subscription_url":"https://api.github.com/repos/mediasuitenz/tech-stack/subscription","commits_url":"https://api.github.com/repos/mediasuitenz/tech-stack/commits{/sha}","git_commits_url":"https://api.github.com/repos/mediasuitenz/tech-stack/git/commits{/sha}","comments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/comments{/number}","issue_comment_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/comments{/number}","contents_url":"https://api.github.com/repos/mediasuitenz/tech-stack/contents/{+path}","compare_url":"https://api.github.com/repos/mediasuitenz/tech-stack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mediasuitenz/tech-stack/merges","archive_url":"https://api.github.com/repos/mediasuitenz/tech-stack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mediasuitenz/tech-stack/downloads","issues_url":"https://api.github.com/repos/mediasuitenz/tech-stack/issues{/number}","pulls_url":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls{/number}","milestones_url":"https://api.github.com/repos/mediasuitenz/tech-stack/milestones{/number}","notifications_url":"https://api.github.com/repos/mediasuitenz/tech-stack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mediasuitenz/tech-stack/labels{/name}","releases_url":"https://api.github.com/repos/mediasuitenz/tech-stack/releases{/id}","deployments_url":"https://api.github.com/repos/mediasuitenz/tech-stack/deployments","created_at":"2015-03-13T01:04:12Z","updated_at":"2016-04-10T06:16:21Z","pushed_at":"2016-08-09T02:17:29Z","git_url":"git://github.com/mediasuitenz/tech-stack.git","ssh_url":"git@github.com:mediasuitenz/tech-stack.git","clone_url":"https://github.com/mediasuitenz/tech-stack.git","svn_url":"https://github.com/mediasuitenz/tech-stack","homepage":null,"size":28,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11"},"html":{"href":"https://github.com/mediasuitenz/tech-stack/pull/11"},"issue":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/11"},"comments":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/mediasuitenz/tech-stack/statuses/629f63bfa201b09d759a7707085d7354fb5dc87f"}}}}
{"actor":{"display_login":"pnw"}}