{"action":"created","comment":{"url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/comments/87563728","pull_request_review_id":8172010,"id":87563728,"diff_hunk":"@@ -0,0 +1,52 @@\n+const ValidationError = require('../errors/validation-error')\n+const FieldValidator = require('../validators/field-validator')\n+const ErrorHandler = require('../validators/error-handler')\n+const fs = require('fs')\n+const dateFormatter = require('../date-formatter')\n+const documentTypeEnum = require('../../constants/document-type-enum')\n+\n+class FileUpload {\n+  constructor (claimId, documentType, claimExpenseId, file, fileTypeError, alternative) {\n+    this.file = file\n+    this.alternative = alternative\n+    this.fileTypeError = fileTypeError\n+    this.IsValid()\n+    this.path = file.path\n+    this.claimId = claimId\n+    this.documentType = documentTypeEnum[documentType]\n+    this.claimExpenseId = claimExpenseId\n+    this.dateSubmitted = dateFormatter.now().toDate()\n+\n+    if (file) {\n+      this.documentStatus = 'uploaded'\n+    } else {\n+      this.documentStatus = alternative\n+    }\n+  }\n+\n+  IsValid () {\n+    var errors = ErrorHandler()\n+\n+    if (this.fileTypeError) {\n+      throw new ValidationError({upload: ['File uploaded was not an image or pdf']})\n+    }\n+\n+    if (!this.file) {\n+      FieldValidator(this.alternative, 'upload', errors)\n+        .isRequired()\n+    }\n+\n+    if (this.file && this.alternative) {\n+      fs.unlinkSync(this.file.path)\n+      throw new ValidationError({upload: ['Both file uploaded and alternative option selected, please do just one']})","path":"app/services/domain/file-upload.js","position":41,"original_position":41,"commit_id":"fc13d1d023906b168bd4d55c5061757d40af3317","original_commit_id":"fc13d1d023906b168bd4d55c5061757d40af3317","user":{"login":"stevenalexander","id":1783543,"avatar_url":"https://avatars.githubusercontent.com/u/1783543?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenalexander","html_url":"https://github.com/stevenalexander","followers_url":"https://api.github.com/users/stevenalexander/followers","following_url":"https://api.github.com/users/stevenalexander/following{/other_user}","gists_url":"https://api.github.com/users/stevenalexander/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenalexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenalexander/subscriptions","organizations_url":"https://api.github.com/users/stevenalexander/orgs","repos_url":"https://api.github.com/users/stevenalexander/repos","events_url":"https://api.github.com/users/stevenalexander/events{/privacy}","received_events_url":"https://api.github.com/users/stevenalexander/received_events","type":"User","site_admin":false},"body":"bad message, `Both file uploaded and alternative option selected` (don't use please)","created_at":"2016-11-11T10:03:10Z","updated_at":"2016-11-11T10:03:10Z","html_url":"https://github.com/ministryofjustice/apvs-external-web/pull/161#discussion_r87563728","pull_request_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161","_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/comments/87563728"},"html":{"href":"https://github.com/ministryofjustice/apvs-external-web/pull/161#discussion_r87563728"},"pull_request":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161"}}},"pull_request":{"url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161","id":93304609,"html_url":"https://github.com/ministryofjustice/apvs-external-web/pull/161","diff_url":"https://github.com/ministryofjustice/apvs-external-web/pull/161.diff","patch_url":"https://github.com/ministryofjustice/apvs-external-web/pull/161.patch","issue_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/161","number":161,"state":"open","locked":false,"title":"Feature/apvs 672/upload file functionality","user":{"login":"msjhall138","id":5646670,"avatar_url":"https://avatars.githubusercontent.com/u/5646670?v=3","gravatar_id":"","url":"https://api.github.com/users/msjhall138","html_url":"https://github.com/msjhall138","followers_url":"https://api.github.com/users/msjhall138/followers","following_url":"https://api.github.com/users/msjhall138/following{/other_user}","gists_url":"https://api.github.com/users/msjhall138/gists{/gist_id}","starred_url":"https://api.github.com/users/msjhall138/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/msjhall138/subscriptions","organizations_url":"https://api.github.com/users/msjhall138/orgs","repos_url":"https://api.github.com/users/msjhall138/repos","events_url":"https://api.github.com/users/msjhall138/events{/privacy}","received_events_url":"https://api.github.com/users/msjhall138/received_events","type":"User","site_admin":false},"body":"Apvs 672 - upload file functionality\r\n \r\n* Upload function using multer\r\n* File upload domain\r\n* Test for domain\r\n* Validation for upload and domain\r\n* Tests for validation\r\n* Document check to create directories if they do not exist\r\n* Config updates for configurable values\r\n* DB call to insert Claim Document\r\n* Integration helper update\r\n* Integration tests\r\n\r\n## Checklist\r\n\r\n- [x] Unit tests\r\n- [ ] End-to-End tests\r\n- [x] Code coverage checked\r\n- [x] Coding standards\r\n- [x] Error Handling\r\n- [ ] Security/performance considered?\r\n- [ ] Deployment changes considered?\r\n- [ ] README updated\r\n","created_at":"2016-11-11T09:44:48Z","updated_at":"2016-11-11T10:03:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4d5e2a7c01f2439fc4ee35ac395fa2938619c982","assignee":{"login":"stevenalexander","id":1783543,"avatar_url":"https://avatars.githubusercontent.com/u/1783543?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenalexander","html_url":"https://github.com/stevenalexander","followers_url":"https://api.github.com/users/stevenalexander/followers","following_url":"https://api.github.com/users/stevenalexander/following{/other_user}","gists_url":"https://api.github.com/users/stevenalexander/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenalexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenalexander/subscriptions","organizations_url":"https://api.github.com/users/stevenalexander/orgs","repos_url":"https://api.github.com/users/stevenalexander/repos","events_url":"https://api.github.com/users/stevenalexander/events{/privacy}","received_events_url":"https://api.github.com/users/stevenalexander/received_events","type":"User","site_admin":false},"assignees":[{"login":"stevenalexander","id":1783543,"avatar_url":"https://avatars.githubusercontent.com/u/1783543?v=3","gravatar_id":"","url":"https://api.github.com/users/stevenalexander","html_url":"https://github.com/stevenalexander","followers_url":"https://api.github.com/users/stevenalexander/followers","following_url":"https://api.github.com/users/stevenalexander/following{/other_user}","gists_url":"https://api.github.com/users/stevenalexander/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenalexander/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenalexander/subscriptions","organizations_url":"https://api.github.com/users/stevenalexander/orgs","repos_url":"https://api.github.com/users/stevenalexander/repos","events_url":"https://api.github.com/users/stevenalexander/events{/privacy}","received_events_url":"https://api.github.com/users/stevenalexander/received_events","type":"User","site_admin":false},{"login":"pwright08","id":9826034,"avatar_url":"https://avatars.githubusercontent.com/u/9826034?v=3","gravatar_id":"","url":"https://api.github.com/users/pwright08","html_url":"https://github.com/pwright08","followers_url":"https://api.github.com/users/pwright08/followers","following_url":"https://api.github.com/users/pwright08/following{/other_user}","gists_url":"https://api.github.com/users/pwright08/gists{/gist_id}","starred_url":"https://api.github.com/users/pwright08/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pwright08/subscriptions","organizations_url":"https://api.github.com/users/pwright08/orgs","repos_url":"https://api.github.com/users/pwright08/repos","events_url":"https://api.github.com/users/pwright08/events{/privacy}","received_events_url":"https://api.github.com/users/pwright08/received_events","type":"User","site_admin":false},{"login":"tmrowe","id":12531502,"avatar_url":"https://avatars.githubusercontent.com/u/12531502?v=3","gravatar_id":"","url":"https://api.github.com/users/tmrowe","html_url":"https://github.com/tmrowe","followers_url":"https://api.github.com/users/tmrowe/followers","following_url":"https://api.github.com/users/tmrowe/following{/other_user}","gists_url":"https://api.github.com/users/tmrowe/gists{/gist_id}","starred_url":"https://api.github.com/users/tmrowe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmrowe/subscriptions","organizations_url":"https://api.github.com/users/tmrowe/orgs","repos_url":"https://api.github.com/users/tmrowe/repos","events_url":"https://api.github.com/users/tmrowe/events{/privacy}","received_events_url":"https://api.github.com/users/tmrowe/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161/commits","review_comments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161/comments","review_comment_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/161/comments","statuses_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/statuses/fc13d1d023906b168bd4d55c5061757d40af3317","head":{"label":"ministryofjustice:feature/apvs-672/upload-file-functionality","ref":"feature/apvs-672/upload-file-functionality","sha":"fc13d1d023906b168bd4d55c5061757d40af3317","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":70237399,"name":"apvs-external-web","full_name":"ministryofjustice/apvs-external-web","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/apvs-external-web","description":null,"fork":false,"url":"https://api.github.com/repos/ministryofjustice/apvs-external-web","forks_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/forks","keys_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/events","assignees_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/merges","archive_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/deployments","created_at":"2016-10-07T10:36:48Z","updated_at":"2016-10-24T08:43:36Z","pushed_at":"2016-11-11T09:58:17Z","git_url":"git://github.com/ministryofjustice/apvs-external-web.git","ssh_url":"git@github.com:ministryofjustice/apvs-external-web.git","clone_url":"https://github.com/ministryofjustice/apvs-external-web.git","svn_url":"https://github.com/ministryofjustice/apvs-external-web","homepage":null,"size":1074,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":16,"forks":0,"open_issues":16,"watchers":1,"default_branch":"develop"}},"base":{"label":"ministryofjustice:develop","ref":"develop","sha":"7aae06bb9d291ee44aea10d9eef774fe2754afd7","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":70237399,"name":"apvs-external-web","full_name":"ministryofjustice/apvs-external-web","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/apvs-external-web","description":null,"fork":false,"url":"https://api.github.com/repos/ministryofjustice/apvs-external-web","forks_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/forks","keys_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/events","assignees_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/merges","archive_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/apvs-external-web/deployments","created_at":"2016-10-07T10:36:48Z","updated_at":"2016-10-24T08:43:36Z","pushed_at":"2016-11-11T09:58:17Z","git_url":"git://github.com/ministryofjustice/apvs-external-web.git","ssh_url":"git@github.com:ministryofjustice/apvs-external-web.git","clone_url":"https://github.com/ministryofjustice/apvs-external-web.git","svn_url":"https://github.com/ministryofjustice/apvs-external-web","homepage":null,"size":1074,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":16,"forks":0,"open_issues":16,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161"},"html":{"href":"https://github.com/ministryofjustice/apvs-external-web/pull/161"},"issue":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/161"},"comments":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/issues/161/comments"},"review_comments":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161/comments"},"review_comment":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/pulls/161/commits"},"statuses":{"href":"https://api.github.com/repos/ministryofjustice/apvs-external-web/statuses/fc13d1d023906b168bd4d55c5061757d40af3317"}}}}
{"actor":{"display_login":"stevenalexander"}}