{"action":"created","comment":{"url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/comments/23276713","id":23276713,"diff_hunk":"@@ -394,20 +412,89 @@ function createApi(table, provider, sqlGenerator, dependencies) {\n                 });\n             });\n         });\n+    },\n+\n+    /**\n+     * Deletes all messages belonging to the specific mailbox\n+     */\n+    removeByMailbox: function remove(mailbox) {\n+      dependencies.logger.trace('message.removeByMailbox called');\n+\n+      var query = table\n+        .select(table.star())\n+        .from(table)\n+        .where(table['mailbox_id'].equals(mailbox.getId()))\n+        .toQuery();\n+      query = provider.forUpdate(query);\n+\n+      return provider.beginTransaction(true)\n+        .then(function(transaction) {\n+\n+          return transaction.runQuery(query)\n+            .then(function(result) {\n+              var query = table\n+                .delete()\n+                .where(table['mailbox_id'].equals(mailbox.getId()))\n+                .toQuery();\n+\n+              var messages = result.rows;\n+\n+              var x;\n+              for (x in messages) {\n+                messages[x] = convertFromStorage(messages[x]);\n+              }\n+\n+              return transaction.runQuery(query)\n+                .then(function() {\n+                  return transaction.commit();\n+                })\n+                .then(function() {\n+                  dependencies.logger.debug({messages: messages},\n+                                            'Messages removed');\n+                  return messages;","path":"lib/repositories/message.js","position":77,"original_position":77,"commit_id":"3a0935ca1ebdfeb3b105bc6d5145799398b31fc5","original_commit_id":"3a0935ca1ebdfeb3b105bc6d5145799398b31fc5","user":{"login":"samuelg","id":21962,"avatar_url":"https://avatars.githubusercontent.com/u/21962?v=3","gravatar_id":"","url":"https://api.github.com/users/samuelg","html_url":"https://github.com/samuelg","followers_url":"https://api.github.com/users/samuelg/followers","following_url":"https://api.github.com/users/samuelg/following{/other_user}","gists_url":"https://api.github.com/users/samuelg/gists{/gist_id}","starred_url":"https://api.github.com/users/samuelg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samuelg/subscriptions","organizations_url":"https://api.github.com/users/samuelg/orgs","repos_url":"https://api.github.com/users/samuelg/repos","events_url":"https://api.github.com/users/samuelg/events{/privacy}","received_events_url":"https://api.github.com/users/samuelg/received_events","type":"User","site_admin":false},"body":"Why are messages being returned here? The messages won't be fully formed model objects since it doesn't use the common helper methods. The purpose of convertFromStorage is just to get the 'read' property to be converted to a boolean. Not sure this is necessary here. It's used in the message repository to only set the message as read once since it updates MWI and we don't want to duplicate that call.","created_at":"2015-01-21T03:46:55Z","updated_at":"2015-01-21T03:46:55Z","html_url":"https://github.com/asterisk/node-voicemail-data/pull/1#discussion_r23276713","pull_request_url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/comments/23276713"},"html":{"href":"https://github.com/asterisk/node-voicemail-data/pull/1#discussion_r23276713"},"pull_request":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1","id":26387480,"html_url":"https://github.com/asterisk/node-voicemail-data/pull/1","diff_url":"https://github.com/asterisk/node-voicemail-data/pull/1.diff","patch_url":"https://github.com/asterisk/node-voicemail-data/pull/1.patch","issue_url":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/1","number":1,"state":"open","locked":false,"title":"Add DAL functions in preparation for voicemail admin tool","user":{"login":"jrrose","id":768742,"avatar_url":"https://avatars.githubusercontent.com/u/768742?v=3","gravatar_id":"","url":"https://api.github.com/users/jrrose","html_url":"https://github.com/jrrose","followers_url":"https://api.github.com/users/jrrose/followers","following_url":"https://api.github.com/users/jrrose/following{/other_user}","gists_url":"https://api.github.com/users/jrrose/gists{/gist_id}","starred_url":"https://api.github.com/users/jrrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrrose/subscriptions","organizations_url":"https://api.github.com/users/jrrose/orgs","repos_url":"https://api.github.com/users/jrrose/repos","events_url":"https://api.github.com/users/jrrose/events{/privacy}","received_events_url":"https://api.github.com/users/jrrose/received_events","type":"User","site_admin":false},"body":"context: all() - retrieves all contexts\r\nfolder: get(name) - retrieves a folder by name\r\nfolder: getNameOrDTMF(name, dtmf) - retrieves all folders matching either the name or the dtmf\r\nmailbox: allContext(context) - retrieves all mailboxes matching the context\r\nmailbox: countContext(context) - counts all mailboxes matching the context\r\nmessage: removeMailbox(mailbox) - removes all messages belonging to a specific mailbox","created_at":"2014-12-19T17:51:04Z","updated_at":"2015-01-21T03:46:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d96e66dc96f488e6e47bfaac6432ab777654c9e9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1/commits","review_comments_url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1/comments","review_comment_url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/comments/{number}","comments_url":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/1/comments","statuses_url":"https://api.github.com/repos/asterisk/node-voicemail-data/statuses/3a0935ca1ebdfeb3b105bc6d5145799398b31fc5","head":{"label":"jrrose:master","ref":"master","sha":"3a0935ca1ebdfeb3b105bc6d5145799398b31fc5","user":{"login":"jrrose","id":768742,"avatar_url":"https://avatars.githubusercontent.com/u/768742?v=3","gravatar_id":"","url":"https://api.github.com/users/jrrose","html_url":"https://github.com/jrrose","followers_url":"https://api.github.com/users/jrrose/followers","following_url":"https://api.github.com/users/jrrose/following{/other_user}","gists_url":"https://api.github.com/users/jrrose/gists{/gist_id}","starred_url":"https://api.github.com/users/jrrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrrose/subscriptions","organizations_url":"https://api.github.com/users/jrrose/orgs","repos_url":"https://api.github.com/users/jrrose/repos","events_url":"https://api.github.com/users/jrrose/events{/privacy}","received_events_url":"https://api.github.com/users/jrrose/received_events","type":"User","site_admin":false},"repo":{"id":27777555,"name":"node-voicemail-data","full_name":"jrrose/node-voicemail-data","owner":{"login":"jrrose","id":768742,"avatar_url":"https://avatars.githubusercontent.com/u/768742?v=3","gravatar_id":"","url":"https://api.github.com/users/jrrose","html_url":"https://github.com/jrrose","followers_url":"https://api.github.com/users/jrrose/followers","following_url":"https://api.github.com/users/jrrose/following{/other_user}","gists_url":"https://api.github.com/users/jrrose/gists{/gist_id}","starred_url":"https://api.github.com/users/jrrose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jrrose/subscriptions","organizations_url":"https://api.github.com/users/jrrose/orgs","repos_url":"https://api.github.com/users/jrrose/repos","events_url":"https://api.github.com/users/jrrose/events{/privacy}","received_events_url":"https://api.github.com/users/jrrose/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jrrose/node-voicemail-data","description":"Data abstraction layer for voicemail application","fork":true,"url":"https://api.github.com/repos/jrrose/node-voicemail-data","forks_url":"https://api.github.com/repos/jrrose/node-voicemail-data/forks","keys_url":"https://api.github.com/repos/jrrose/node-voicemail-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jrrose/node-voicemail-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jrrose/node-voicemail-data/teams","hooks_url":"https://api.github.com/repos/jrrose/node-voicemail-data/hooks","issue_events_url":"https://api.github.com/repos/jrrose/node-voicemail-data/issues/events{/number}","events_url":"https://api.github.com/repos/jrrose/node-voicemail-data/events","assignees_url":"https://api.github.com/repos/jrrose/node-voicemail-data/assignees{/user}","branches_url":"https://api.github.com/repos/jrrose/node-voicemail-data/branches{/branch}","tags_url":"https://api.github.com/repos/jrrose/node-voicemail-data/tags","blobs_url":"https://api.github.com/repos/jrrose/node-voicemail-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jrrose/node-voicemail-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jrrose/node-voicemail-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/jrrose/node-voicemail-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jrrose/node-voicemail-data/statuses/{sha}","languages_url":"https://api.github.com/repos/jrrose/node-voicemail-data/languages","stargazers_url":"https://api.github.com/repos/jrrose/node-voicemail-data/stargazers","contributors_url":"https://api.github.com/repos/jrrose/node-voicemail-data/contributors","subscribers_url":"https://api.github.com/repos/jrrose/node-voicemail-data/subscribers","subscription_url":"https://api.github.com/repos/jrrose/node-voicemail-data/subscription","commits_url":"https://api.github.com/repos/jrrose/node-voicemail-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/jrrose/node-voicemail-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/jrrose/node-voicemail-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/jrrose/node-voicemail-data/issues/comments/{number}","contents_url":"https://api.github.com/repos/jrrose/node-voicemail-data/contents/{+path}","compare_url":"https://api.github.com/repos/jrrose/node-voicemail-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jrrose/node-voicemail-data/merges","archive_url":"https://api.github.com/repos/jrrose/node-voicemail-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jrrose/node-voicemail-data/downloads","issues_url":"https://api.github.com/repos/jrrose/node-voicemail-data/issues{/number}","pulls_url":"https://api.github.com/repos/jrrose/node-voicemail-data/pulls{/number}","milestones_url":"https://api.github.com/repos/jrrose/node-voicemail-data/milestones{/number}","notifications_url":"https://api.github.com/repos/jrrose/node-voicemail-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jrrose/node-voicemail-data/labels{/name}","releases_url":"https://api.github.com/repos/jrrose/node-voicemail-data/releases{/id}","created_at":"2014-12-09T17:13:43Z","updated_at":"2015-01-12T22:25:46Z","pushed_at":"2015-01-12T22:25:46Z","git_url":"git://github.com/jrrose/node-voicemail-data.git","ssh_url":"git@github.com:jrrose/node-voicemail-data.git","clone_url":"https://github.com/jrrose/node-voicemail-data.git","svn_url":"https://github.com/jrrose/node-voicemail-data","homepage":null,"size":193,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"asterisk:master","ref":"master","sha":"a140af6e969d9bc283a63e68303313daf37d7a5d","user":{"login":"asterisk","id":2914369,"avatar_url":"https://avatars.githubusercontent.com/u/2914369?v=3","gravatar_id":"","url":"https://api.github.com/users/asterisk","html_url":"https://github.com/asterisk","followers_url":"https://api.github.com/users/asterisk/followers","following_url":"https://api.github.com/users/asterisk/following{/other_user}","gists_url":"https://api.github.com/users/asterisk/gists{/gist_id}","starred_url":"https://api.github.com/users/asterisk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterisk/subscriptions","organizations_url":"https://api.github.com/users/asterisk/orgs","repos_url":"https://api.github.com/users/asterisk/repos","events_url":"https://api.github.com/users/asterisk/events{/privacy}","received_events_url":"https://api.github.com/users/asterisk/received_events","type":"Organization","site_admin":false},"repo":{"id":24418492,"name":"node-voicemail-data","full_name":"asterisk/node-voicemail-data","owner":{"login":"asterisk","id":2914369,"avatar_url":"https://avatars.githubusercontent.com/u/2914369?v=3","gravatar_id":"","url":"https://api.github.com/users/asterisk","html_url":"https://github.com/asterisk","followers_url":"https://api.github.com/users/asterisk/followers","following_url":"https://api.github.com/users/asterisk/following{/other_user}","gists_url":"https://api.github.com/users/asterisk/gists{/gist_id}","starred_url":"https://api.github.com/users/asterisk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterisk/subscriptions","organizations_url":"https://api.github.com/users/asterisk/orgs","repos_url":"https://api.github.com/users/asterisk/repos","events_url":"https://api.github.com/users/asterisk/events{/privacy}","received_events_url":"https://api.github.com/users/asterisk/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/asterisk/node-voicemail-data","description":"Data abstraction layer for voicemail application","fork":false,"url":"https://api.github.com/repos/asterisk/node-voicemail-data","forks_url":"https://api.github.com/repos/asterisk/node-voicemail-data/forks","keys_url":"https://api.github.com/repos/asterisk/node-voicemail-data/keys{/key_id}","collaborators_url":"https://api.github.com/repos/asterisk/node-voicemail-data/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/asterisk/node-voicemail-data/teams","hooks_url":"https://api.github.com/repos/asterisk/node-voicemail-data/hooks","issue_events_url":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/events{/number}","events_url":"https://api.github.com/repos/asterisk/node-voicemail-data/events","assignees_url":"https://api.github.com/repos/asterisk/node-voicemail-data/assignees{/user}","branches_url":"https://api.github.com/repos/asterisk/node-voicemail-data/branches{/branch}","tags_url":"https://api.github.com/repos/asterisk/node-voicemail-data/tags","blobs_url":"https://api.github.com/repos/asterisk/node-voicemail-data/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/asterisk/node-voicemail-data/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/asterisk/node-voicemail-data/git/refs{/sha}","trees_url":"https://api.github.com/repos/asterisk/node-voicemail-data/git/trees{/sha}","statuses_url":"https://api.github.com/repos/asterisk/node-voicemail-data/statuses/{sha}","languages_url":"https://api.github.com/repos/asterisk/node-voicemail-data/languages","stargazers_url":"https://api.github.com/repos/asterisk/node-voicemail-data/stargazers","contributors_url":"https://api.github.com/repos/asterisk/node-voicemail-data/contributors","subscribers_url":"https://api.github.com/repos/asterisk/node-voicemail-data/subscribers","subscription_url":"https://api.github.com/repos/asterisk/node-voicemail-data/subscription","commits_url":"https://api.github.com/repos/asterisk/node-voicemail-data/commits{/sha}","git_commits_url":"https://api.github.com/repos/asterisk/node-voicemail-data/git/commits{/sha}","comments_url":"https://api.github.com/repos/asterisk/node-voicemail-data/comments{/number}","issue_comment_url":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/comments/{number}","contents_url":"https://api.github.com/repos/asterisk/node-voicemail-data/contents/{+path}","compare_url":"https://api.github.com/repos/asterisk/node-voicemail-data/compare/{base}...{head}","merges_url":"https://api.github.com/repos/asterisk/node-voicemail-data/merges","archive_url":"https://api.github.com/repos/asterisk/node-voicemail-data/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/asterisk/node-voicemail-data/downloads","issues_url":"https://api.github.com/repos/asterisk/node-voicemail-data/issues{/number}","pulls_url":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls{/number}","milestones_url":"https://api.github.com/repos/asterisk/node-voicemail-data/milestones{/number}","notifications_url":"https://api.github.com/repos/asterisk/node-voicemail-data/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/asterisk/node-voicemail-data/labels{/name}","releases_url":"https://api.github.com/repos/asterisk/node-voicemail-data/releases{/id}","created_at":"2014-09-24T14:34:56Z","updated_at":"2014-11-25T15:49:03Z","pushed_at":"2014-11-25T15:49:03Z","git_url":"git://github.com/asterisk/node-voicemail-data.git","ssh_url":"git@github.com:asterisk/node-voicemail-data.git","clone_url":"https://github.com/asterisk/node-voicemail-data.git","svn_url":"https://github.com/asterisk/node-voicemail-data","homepage":null,"size":284,"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":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1"},"html":{"href":"https://github.com/asterisk/node-voicemail-data/pull/1"},"issue":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/1"},"comments":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/asterisk/node-voicemail-data/statuses/3a0935ca1ebdfeb3b105bc6d5145799398b31fc5"}}}}