{"action":"created","comment":{"url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/comments/45949957","id":45949957,"diff_hunk":"@@ -1,17 +1,194 @@\n 'use strict';\n \n module.exports = () => {\n-\treturn (req, res, next) => {\n-\t\tres.warn = (status, error) => {\n-\t        if (typeof error === 'undefined' ) {\n-\t            error = status;\n-\t            status = 400;\n-\t        }\n-\n-\t        res.status(status)\n-\t            .send(error);\n-\t    };\n-\n-\t    next();\n-\t};\n+    return (req, res, next) => {\n+        let response = {};\n+        const orig_send = res.send;\n+\n+        res.warn = function (status, error) {\n+            if (typeof error === 'undefined' ) {\n+                error = status;\n+                status = 400;\n+            }\n+\n+            res.status(status)\n+                .send(error);\n+        };\n+\n+        res.send = function (data) {\n+            res.send = orig_send;\n+\n+            if (typeof data === 'undefined' && Object.keys(response).length > 0) {\n+                return res.send(JSON.stringify(response));\n+            }\n+\n+            res.send(data);\n+        };\n+\n+        res.data = function (data) {\n+            if (typeof data !== 'object') {\n+                throw new Error(\"Data must be type object.\")\n+            }\n+\n+            // check for reserved keys\n+            if (typeof response.data !== 'object') {\n+                response.data = {};\n+            }\n+\n+            Object.assign(response.data, data);\n+\n+            return res;\n+        };\n+\n+        res.add_data = function () {\n+            let args = get_key_value.apply({}, arguments);\n+\n+            if (typeof args.key !== 'string') {\n+                throw new Error(\"Key must be type string.\")\n+            }\n+\n+            if (typeof response.data !== 'object') {\n+                response.data = {};\n+            }\n+\n+            if (typeof response.data[args.key] === 'undefined') {\n+                response.data[args.key] = [];\n+            }\n+\n+            if (Array.isArray(args.value)) {\n+                response.data[args.key] = response.data[args.key].concat(args.value);\n+            } else {\n+                response.data[args.key].push(args.value);\n+            }\n+\n+            return res;\n+        };\n+\n+        res.items = function (items) {","path":"lib/res_extended.js","position":80,"original_position":80,"commit_id":"5cab8893bb9bebc812d51cd17a3ef442a5c0631a","original_commit_id":"5cab8893bb9bebc812d51cd17a3ef442a5c0631a","user":{"login":"ravenjohn","id":3425521,"avatar_url":"https://avatars.githubusercontent.com/u/3425521?v=3","gravatar_id":"","url":"https://api.github.com/users/ravenjohn","html_url":"https://github.com/ravenjohn","followers_url":"https://api.github.com/users/ravenjohn/followers","following_url":"https://api.github.com/users/ravenjohn/following{/other_user}","gists_url":"https://api.github.com/users/ravenjohn/gists{/gist_id}","starred_url":"https://api.github.com/users/ravenjohn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravenjohn/subscriptions","organizations_url":"https://api.github.com/users/ravenjohn/orgs","repos_url":"https://api.github.com/users/ravenjohn/repos","events_url":"https://api.github.com/users/ravenjohn/events{/privacy}","received_events_url":"https://api.github.com/users/ravenjohn/received_events","type":"User","site_admin":false},"body":"anon","created_at":"2015-11-26T07:37:29Z","updated_at":"2015-11-26T07:37:29Z","html_url":"https://github.com/anyTV/anytv-node-boilerplate/pull/8#discussion_r45949957","pull_request_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/comments/45949957"},"html":{"href":"https://github.com/anyTV/anytv-node-boilerplate/pull/8#discussion_r45949957"},"pull_request":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8","id":51799621,"html_url":"https://github.com/anyTV/anytv-node-boilerplate/pull/8","diff_url":"https://github.com/anyTV/anytv-node-boilerplate/pull/8.diff","patch_url":"https://github.com/anyTV/anytv-node-boilerplate/pull/8.patch","issue_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/8","number":8,"state":"open","locked":false,"title":"add method for handling api response; updated user controller to use …","user":{"login":"airondumael","id":4447799,"avatar_url":"https://avatars.githubusercontent.com/u/4447799?v=3","gravatar_id":"","url":"https://api.github.com/users/airondumael","html_url":"https://github.com/airondumael","followers_url":"https://api.github.com/users/airondumael/followers","following_url":"https://api.github.com/users/airondumael/following{/other_user}","gists_url":"https://api.github.com/users/airondumael/gists{/gist_id}","starred_url":"https://api.github.com/users/airondumael/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/airondumael/subscriptions","organizations_url":"https://api.github.com/users/airondumael/orgs","repos_url":"https://api.github.com/users/airondumael/repos","events_url":"https://api.github.com/users/airondumael/events{/privacy}","received_events_url":"https://api.github.com/users/airondumael/received_events","type":"User","site_admin":false},"body":"need comments.","created_at":"2015-11-25T14:21:34Z","updated_at":"2015-11-26T07:37:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b408c13c2b12e7482f38591e59099119aca662cc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8/commits","review_comments_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8/comments","review_comment_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/8/comments","statuses_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/statuses/5cab8893bb9bebc812d51cd17a3ef442a5c0631a","head":{"label":"anyTV:update_res_extend","ref":"update_res_extend","sha":"5cab8893bb9bebc812d51cd17a3ef442a5c0631a","user":{"login":"anyTV","id":3164673,"avatar_url":"https://avatars.githubusercontent.com/u/3164673?v=3","gravatar_id":"","url":"https://api.github.com/users/anyTV","html_url":"https://github.com/anyTV","followers_url":"https://api.github.com/users/anyTV/followers","following_url":"https://api.github.com/users/anyTV/following{/other_user}","gists_url":"https://api.github.com/users/anyTV/gists{/gist_id}","starred_url":"https://api.github.com/users/anyTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyTV/subscriptions","organizations_url":"https://api.github.com/users/anyTV/orgs","repos_url":"https://api.github.com/users/anyTV/repos","events_url":"https://api.github.com/users/anyTV/events{/privacy}","received_events_url":"https://api.github.com/users/anyTV/received_events","type":"Organization","site_admin":false},"repo":{"id":29559622,"name":"anytv-node-boilerplate","full_name":"anyTV/anytv-node-boilerplate","owner":{"login":"anyTV","id":3164673,"avatar_url":"https://avatars.githubusercontent.com/u/3164673?v=3","gravatar_id":"","url":"https://api.github.com/users/anyTV","html_url":"https://github.com/anyTV","followers_url":"https://api.github.com/users/anyTV/followers","following_url":"https://api.github.com/users/anyTV/following{/other_user}","gists_url":"https://api.github.com/users/anyTV/gists{/gist_id}","starred_url":"https://api.github.com/users/anyTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyTV/subscriptions","organizations_url":"https://api.github.com/users/anyTV/orgs","repos_url":"https://api.github.com/users/anyTV/repos","events_url":"https://api.github.com/users/anyTV/events{/privacy}","received_events_url":"https://api.github.com/users/anyTV/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/anyTV/anytv-node-boilerplate","description":"anyTV boilerplate for creating backend API on node.js","fork":false,"url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate","forks_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/forks","keys_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/teams","hooks_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/hooks","issue_events_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/events{/number}","events_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/events","assignees_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/assignees{/user}","branches_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/branches{/branch}","tags_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/tags","blobs_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/refs{/sha}","trees_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/statuses/{sha}","languages_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/languages","stargazers_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/stargazers","contributors_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/contributors","subscribers_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/subscribers","subscription_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/subscription","commits_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/commits{/sha}","git_commits_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/commits{/sha}","comments_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/comments{/number}","issue_comment_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/comments{/number}","contents_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/contents/{+path}","compare_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/merges","archive_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/downloads","issues_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues{/number}","pulls_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls{/number}","milestones_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/milestones{/number}","notifications_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/labels{/name}","releases_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/releases{/id}","created_at":"2015-01-20T22:57:45Z","updated_at":"2015-05-07T08:31:33Z","pushed_at":"2015-11-25T15:09:21Z","git_url":"git://github.com/anyTV/anytv-node-boilerplate.git","ssh_url":"git@github.com:anyTV/anytv-node-boilerplate.git","clone_url":"https://github.com/anyTV/anytv-node-boilerplate.git","svn_url":"https://github.com/anyTV/anytv-node-boilerplate","homepage":null,"size":70,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"anyTV:master","ref":"master","sha":"87d7f6591c0f3dd423eabde43d8a72f4b248925d","user":{"login":"anyTV","id":3164673,"avatar_url":"https://avatars.githubusercontent.com/u/3164673?v=3","gravatar_id":"","url":"https://api.github.com/users/anyTV","html_url":"https://github.com/anyTV","followers_url":"https://api.github.com/users/anyTV/followers","following_url":"https://api.github.com/users/anyTV/following{/other_user}","gists_url":"https://api.github.com/users/anyTV/gists{/gist_id}","starred_url":"https://api.github.com/users/anyTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyTV/subscriptions","organizations_url":"https://api.github.com/users/anyTV/orgs","repos_url":"https://api.github.com/users/anyTV/repos","events_url":"https://api.github.com/users/anyTV/events{/privacy}","received_events_url":"https://api.github.com/users/anyTV/received_events","type":"Organization","site_admin":false},"repo":{"id":29559622,"name":"anytv-node-boilerplate","full_name":"anyTV/anytv-node-boilerplate","owner":{"login":"anyTV","id":3164673,"avatar_url":"https://avatars.githubusercontent.com/u/3164673?v=3","gravatar_id":"","url":"https://api.github.com/users/anyTV","html_url":"https://github.com/anyTV","followers_url":"https://api.github.com/users/anyTV/followers","following_url":"https://api.github.com/users/anyTV/following{/other_user}","gists_url":"https://api.github.com/users/anyTV/gists{/gist_id}","starred_url":"https://api.github.com/users/anyTV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anyTV/subscriptions","organizations_url":"https://api.github.com/users/anyTV/orgs","repos_url":"https://api.github.com/users/anyTV/repos","events_url":"https://api.github.com/users/anyTV/events{/privacy}","received_events_url":"https://api.github.com/users/anyTV/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/anyTV/anytv-node-boilerplate","description":"anyTV boilerplate for creating backend API on node.js","fork":false,"url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate","forks_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/forks","keys_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/teams","hooks_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/hooks","issue_events_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/events{/number}","events_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/events","assignees_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/assignees{/user}","branches_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/branches{/branch}","tags_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/tags","blobs_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/refs{/sha}","trees_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/statuses/{sha}","languages_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/languages","stargazers_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/stargazers","contributors_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/contributors","subscribers_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/subscribers","subscription_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/subscription","commits_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/commits{/sha}","git_commits_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/git/commits{/sha}","comments_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/comments{/number}","issue_comment_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/comments{/number}","contents_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/contents/{+path}","compare_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/merges","archive_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/downloads","issues_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues{/number}","pulls_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls{/number}","milestones_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/milestones{/number}","notifications_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/labels{/name}","releases_url":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/releases{/id}","created_at":"2015-01-20T22:57:45Z","updated_at":"2015-05-07T08:31:33Z","pushed_at":"2015-11-25T15:09:21Z","git_url":"git://github.com/anyTV/anytv-node-boilerplate.git","ssh_url":"git@github.com:anyTV/anytv-node-boilerplate.git","clone_url":"https://github.com/anyTV/anytv-node-boilerplate.git","svn_url":"https://github.com/anyTV/anytv-node-boilerplate","homepage":null,"size":70,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8"},"html":{"href":"https://github.com/anyTV/anytv-node-boilerplate/pull/8"},"issue":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/8"},"comments":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/anyTV/anytv-node-boilerplate/statuses/5cab8893bb9bebc812d51cd17a3ef442a5c0631a"}}}}