{"action":"created","comment":{"url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/comments/167361638","pull_request_review_id":95580894,"id":167361638,"diff_hunk":"@@ -20,14 +25,55 @@ var UsersSchema = new mongoose.Schema({\n         default: Date.now\n     },\n     user_type: {\n-        type: [{\n-            type: String,\n-            enum: ['student', 'recruiter']\n-        }],\n-        default: ['student']\n+        type: String,\n+        default: 'student',\n+        validate: {\n+            isAsync: true,\n+            validator: function(v, cb) {\n+                if (v === 'student') {\n+                    cb(true);\n+                } else if (v === 'recruiter') {\n+                    var msg = 'recruiter must have a valid employer_id';\n+                    if(/[a-f0-9]{24}/.test(this.employer_id)) {\n+                        Employer.count({_id: ObjectId(this.employer_id)}, function (err, count){ \n+                            if (err) {\n+                                cb(false, msg); //some kind of server error\n+                            } else if (!(count > 0)) {\n+                                cb(false, msg); //no employer found with this employer_id\n+                            } else {\n+                                cb(true);\n+                            }\n+                        }); \n+                    } else {\n+                        cb(false, msg); //employer_id isn't a 24 character hex string\n+                    }\n+                } else {\n+                    cb(false, 'user_type must be student or recruiter');\n+                }\n+            },\n+            message: 'Error validating user_type'\n+        },\n     },\n     employer_id: {\n         type: String,\n+        validate: {","path":"src/api/models/users.js","position":55,"original_position":55,"commit_id":"a828b5e48ab19132682a8c565feb2728d2a4c77b","original_commit_id":"a828b5e48ab19132682a8c565feb2728d2a4c77b","user":{"login":"brianwang9100","id":7969184,"avatar_url":"https://avatars2.githubusercontent.com/u/7969184?v=4","gravatar_id":"","url":"https://api.github.com/users/brianwang9100","html_url":"https://github.com/brianwang9100","followers_url":"https://api.github.com/users/brianwang9100/followers","following_url":"https://api.github.com/users/brianwang9100/following{/other_user}","gists_url":"https://api.github.com/users/brianwang9100/gists{/gist_id}","starred_url":"https://api.github.com/users/brianwang9100/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brianwang9100/subscriptions","organizations_url":"https://api.github.com/users/brianwang9100/orgs","repos_url":"https://api.github.com/users/brianwang9100/repos","events_url":"https://api.github.com/users/brianwang9100/events{/privacy}","received_events_url":"https://api.github.com/users/brianwang9100/received_events","type":"User","site_admin":false},"body":"Oh and then remove the validator cause you don't need it.\r\n\r\nThen you can probably add a required function\r\n```\r\n    employer_id: {\r\n        type: Schema.Types.ObjectId,\r\n        ref: 'Employer',\r\n        required: function() {\r\n            return this.user_type === 'recruiter';\r\n        },\r\n        default: null,\r\n    }\r\n```","created_at":"2018-02-09T22:23:19Z","updated_at":"2018-02-09T22:32:27Z","html_url":"https://github.com/wdjg/coccareerfairapp-server/pull/50#discussion_r167361638","pull_request_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/comments/167361638"},"html":{"href":"https://github.com/wdjg/coccareerfairapp-server/pull/50#discussion_r167361638"},"pull_request":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50"}},"in_reply_to_id":167361120},"pull_request":{"url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50","id":168313570,"html_url":"https://github.com/wdjg/coccareerfairapp-server/pull/50","diff_url":"https://github.com/wdjg/coccareerfairapp-server/pull/50.diff","patch_url":"https://github.com/wdjg/coccareerfairapp-server/pull/50.patch","issue_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/50","number":50,"state":"open","locked":false,"title":"add user_type and employer_id validation on user registration","user":{"login":"jhayes45","id":35344365,"avatar_url":"https://avatars3.githubusercontent.com/u/35344365?v=4","gravatar_id":"","url":"https://api.github.com/users/jhayes45","html_url":"https://github.com/jhayes45","followers_url":"https://api.github.com/users/jhayes45/followers","following_url":"https://api.github.com/users/jhayes45/following{/other_user}","gists_url":"https://api.github.com/users/jhayes45/gists{/gist_id}","starred_url":"https://api.github.com/users/jhayes45/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhayes45/subscriptions","organizations_url":"https://api.github.com/users/jhayes45/orgs","repos_url":"https://api.github.com/users/jhayes45/repos","events_url":"https://api.github.com/users/jhayes45/events{/privacy}","received_events_url":"https://api.github.com/users/jhayes45/received_events","type":"User","site_admin":false},"body":"User model now validates (on registration):\r\n\r\n-If an employer_id is provided at all, it must be a valid employer_id (that already exists).\r\n-User type must be student or recruiter.\r\n-If user type is recruiter, employer_id must also be provided & be valid.\r\n\r\nTested employer_ids:\r\n-blank, single digit, 24 hex characters (but invalid), 24 hex characters (and valid)\r\n\r\nTested user_types:\r\n-blank, student, recruiter, ffdsa\r\n\r\n","created_at":"2018-02-09T18:42:53Z","updated_at":"2018-02-09T22:32:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5356d068d1e27899311747ccd2949a40b8dad643","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50/commits","review_comments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50/comments","review_comment_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/50/comments","statuses_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/statuses/a828b5e48ab19132682a8c565feb2728d2a4c77b","head":{"label":"wdjg:issue47","ref":"issue47","sha":"a828b5e48ab19132682a8c565feb2728d2a4c77b","user":{"login":"wdjg","id":35708109,"avatar_url":"https://avatars3.githubusercontent.com/u/35708109?v=4","gravatar_id":"","url":"https://api.github.com/users/wdjg","html_url":"https://github.com/wdjg","followers_url":"https://api.github.com/users/wdjg/followers","following_url":"https://api.github.com/users/wdjg/following{/other_user}","gists_url":"https://api.github.com/users/wdjg/gists{/gist_id}","starred_url":"https://api.github.com/users/wdjg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdjg/subscriptions","organizations_url":"https://api.github.com/users/wdjg/orgs","repos_url":"https://api.github.com/users/wdjg/repos","events_url":"https://api.github.com/users/wdjg/events{/privacy}","received_events_url":"https://api.github.com/users/wdjg/received_events","type":"Organization","site_admin":false},"repo":{"id":118518890,"name":"coccareerfairapp-server","full_name":"wdjg/coccareerfairapp-server","owner":{"login":"wdjg","id":35708109,"avatar_url":"https://avatars3.githubusercontent.com/u/35708109?v=4","gravatar_id":"","url":"https://api.github.com/users/wdjg","html_url":"https://github.com/wdjg","followers_url":"https://api.github.com/users/wdjg/followers","following_url":"https://api.github.com/users/wdjg/following{/other_user}","gists_url":"https://api.github.com/users/wdjg/gists{/gist_id}","starred_url":"https://api.github.com/users/wdjg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdjg/subscriptions","organizations_url":"https://api.github.com/users/wdjg/orgs","repos_url":"https://api.github.com/users/wdjg/repos","events_url":"https://api.github.com/users/wdjg/events{/privacy}","received_events_url":"https://api.github.com/users/wdjg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wdjg/coccareerfairapp-server","description":"Backend for coc career fair written in Javascript on the MEAN stack","fork":false,"url":"https://api.github.com/repos/wdjg/coccareerfairapp-server","forks_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/forks","keys_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/teams","hooks_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/hooks","issue_events_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/events{/number}","events_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/events","assignees_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/assignees{/user}","branches_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/branches{/branch}","tags_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/tags","blobs_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/statuses/{sha}","languages_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/languages","stargazers_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/stargazers","contributors_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/contributors","subscribers_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/subscribers","subscription_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/subscription","commits_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/contents/{+path}","compare_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/merges","archive_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/downloads","issues_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues{/number}","pulls_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls{/number}","milestones_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/milestones{/number}","notifications_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/labels{/name}","releases_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/releases{/id}","deployments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/deployments","created_at":"2018-01-22T21:41:21Z","updated_at":"2018-02-04T04:56:57Z","pushed_at":"2018-02-09T21:56:40Z","git_url":"git://github.com/wdjg/coccareerfairapp-server.git","ssh_url":"git@github.com:wdjg/coccareerfairapp-server.git","clone_url":"https://github.com/wdjg/coccareerfairapp-server.git","svn_url":"https://github.com/wdjg/coccareerfairapp-server","homepage":null,"size":7242,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":35,"license":null,"forks":0,"open_issues":35,"watchers":1,"default_branch":"master"}},"base":{"label":"wdjg:master","ref":"master","sha":"668ce9c792a2700d528d072ee8a28fdf6e46228f","user":{"login":"wdjg","id":35708109,"avatar_url":"https://avatars3.githubusercontent.com/u/35708109?v=4","gravatar_id":"","url":"https://api.github.com/users/wdjg","html_url":"https://github.com/wdjg","followers_url":"https://api.github.com/users/wdjg/followers","following_url":"https://api.github.com/users/wdjg/following{/other_user}","gists_url":"https://api.github.com/users/wdjg/gists{/gist_id}","starred_url":"https://api.github.com/users/wdjg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdjg/subscriptions","organizations_url":"https://api.github.com/users/wdjg/orgs","repos_url":"https://api.github.com/users/wdjg/repos","events_url":"https://api.github.com/users/wdjg/events{/privacy}","received_events_url":"https://api.github.com/users/wdjg/received_events","type":"Organization","site_admin":false},"repo":{"id":118518890,"name":"coccareerfairapp-server","full_name":"wdjg/coccareerfairapp-server","owner":{"login":"wdjg","id":35708109,"avatar_url":"https://avatars3.githubusercontent.com/u/35708109?v=4","gravatar_id":"","url":"https://api.github.com/users/wdjg","html_url":"https://github.com/wdjg","followers_url":"https://api.github.com/users/wdjg/followers","following_url":"https://api.github.com/users/wdjg/following{/other_user}","gists_url":"https://api.github.com/users/wdjg/gists{/gist_id}","starred_url":"https://api.github.com/users/wdjg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wdjg/subscriptions","organizations_url":"https://api.github.com/users/wdjg/orgs","repos_url":"https://api.github.com/users/wdjg/repos","events_url":"https://api.github.com/users/wdjg/events{/privacy}","received_events_url":"https://api.github.com/users/wdjg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/wdjg/coccareerfairapp-server","description":"Backend for coc career fair written in Javascript on the MEAN stack","fork":false,"url":"https://api.github.com/repos/wdjg/coccareerfairapp-server","forks_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/forks","keys_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/teams","hooks_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/hooks","issue_events_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/events{/number}","events_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/events","assignees_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/assignees{/user}","branches_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/branches{/branch}","tags_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/tags","blobs_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/statuses/{sha}","languages_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/languages","stargazers_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/stargazers","contributors_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/contributors","subscribers_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/subscribers","subscription_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/subscription","commits_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/contents/{+path}","compare_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/merges","archive_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/downloads","issues_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues{/number}","pulls_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls{/number}","milestones_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/milestones{/number}","notifications_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/labels{/name}","releases_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/releases{/id}","deployments_url":"https://api.github.com/repos/wdjg/coccareerfairapp-server/deployments","created_at":"2018-01-22T21:41:21Z","updated_at":"2018-02-04T04:56:57Z","pushed_at":"2018-02-09T21:56:40Z","git_url":"git://github.com/wdjg/coccareerfairapp-server.git","ssh_url":"git@github.com:wdjg/coccareerfairapp-server.git","clone_url":"https://github.com/wdjg/coccareerfairapp-server.git","svn_url":"https://github.com/wdjg/coccareerfairapp-server","homepage":null,"size":7242,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":35,"license":null,"forks":0,"open_issues":35,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50"},"html":{"href":"https://github.com/wdjg/coccareerfairapp-server/pull/50"},"issue":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/50"},"comments":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/issues/50/comments"},"review_comments":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50/comments"},"review_comment":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/pulls/50/commits"},"statuses":{"href":"https://api.github.com/repos/wdjg/coccareerfairapp-server/statuses/a828b5e48ab19132682a8c565feb2728d2a4c77b"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"brianwang9100"}}