{"action":"created","comment":{"url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/comments/204507368","pull_request_review_id":139597353,"id":204507368,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNDUwNzM2OA==","diff_hunk":"@@ -15,16 +21,54 @@ const connectionPromise = MongoClient\n   .connect(mongoUrl, { promiseLibrary: Promise, useNewUrlParser: true })\r\n   .then(client => client.db().collection('scores'))\r\n \r\n+function _validateScore (score) {\r\n+  let retError = { 'status': 'ok', 'errors': '' }\r\n+\r\n+  if (typeof score.teamNumber !== 'number' || score.match == null || score.score == null) {\r\n+    retError.status = 'loud-fail'\r\n+    if (typeof score.teamNumber !== 'number') { retError.errors += 'team number ' }\r\n+    if (score.score == null) { retError.errors += 'score ' }\r\n+    if (score.match == null) { retError.errors += 'match ' }\r\n+  }\r\n+\r\n+  if (score.signature.isEmpty) {\r\n+    retError.errors += 'signature '\r\n+    retError.status = retError.status === 'loud-fail' ? 'loud-fail' : 'silent-fail'\r\n+  }\r\n+\r\n+  return retError\r\n+}\r\n+\r\n const adminAction = authroizationMiddlware(['admin', 'scorekeeper', 'development'])\r\n \r\n router.post('/create', (req, res) => {\r\n-  connectionPromise\r\n-    .then(scoringCollection => scoringCollection.save(req.body))\r\n-    .then(() => res.status(201).send())\r\n-    .catch(err => {\r\n-      req.logger.error(err.message)\r\n-      res.status(500).send('A problem occoured while trying to save score.')\r\n-    })\r\n+  const scoreValidation = _validateScore(req.body)\r\n+\r\n+  if (scoreValidation.status !== 'ok') {\r\n+    req.logger.error('Invalid score, missing ' + scoreValidation.errors + '. ' + scoreValidation.status + '.')\r\n+  }\r\n+\r\n+  if (scoreValidation.status !== 'loud-fail') {\r\n+    connectionPromise\r\n+      .then(scoringCollection => {\r\n+        scoringCollection.save(req.body)\r","path":"server/scores.js","position":54,"original_position":54,"commit_id":"c5d773321e0f5a7878f48a6647badfc971e8bd42","original_commit_id":"c5d773321e0f5a7878f48a6647badfc971e8bd42","user":{"login":"YonatanGideoni","id":20254893,"node_id":"MDQ6VXNlcjIwMjU0ODkz","avatar_url":"https://avatars0.githubusercontent.com/u/20254893?v=4","gravatar_id":"","url":"https://api.github.com/users/YonatanGideoni","html_url":"https://github.com/YonatanGideoni","followers_url":"https://api.github.com/users/YonatanGideoni/followers","following_url":"https://api.github.com/users/YonatanGideoni/following{/other_user}","gists_url":"https://api.github.com/users/YonatanGideoni/gists{/gist_id}","starred_url":"https://api.github.com/users/YonatanGideoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YonatanGideoni/subscriptions","organizations_url":"https://api.github.com/users/YonatanGideoni/orgs","repos_url":"https://api.github.com/users/YonatanGideoni/repos","events_url":"https://api.github.com/users/YonatanGideoni/events{/privacy}","received_events_url":"https://api.github.com/users/YonatanGideoni/received_events","type":"User","site_admin":false},"body":"Is the existing if on line 51 which checks whether or not there is a loud fail precisely what you want here? It also indeed does throw a 422 if there is a loud fail.","created_at":"2018-07-23T18:23:58Z","updated_at":"2018-07-23T18:23:58Z","html_url":"https://github.com/FirstLegoLeague/scoring/pull/23#discussion_r204507368","pull_request_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/comments/204507368"},"html":{"href":"https://github.com/FirstLegoLeague/scoring/pull/23#discussion_r204507368"},"pull_request":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23"}},"in_reply_to_id":204375831},"pull_request":{"url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23","id":203047874,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAzMDQ3ODc0","html_url":"https://github.com/FirstLegoLeague/scoring/pull/23","diff_url":"https://github.com/FirstLegoLeague/scoring/pull/23.diff","patch_url":"https://github.com/FirstLegoLeague/scoring/pull/23.patch","issue_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/23","number":23,"state":"open","locked":false,"title":"Server side validation","user":{"login":"YonatanGideoni","id":20254893,"node_id":"MDQ6VXNlcjIwMjU0ODkz","avatar_url":"https://avatars0.githubusercontent.com/u/20254893?v=4","gravatar_id":"","url":"https://api.github.com/users/YonatanGideoni","html_url":"https://github.com/YonatanGideoni","followers_url":"https://api.github.com/users/YonatanGideoni/followers","following_url":"https://api.github.com/users/YonatanGideoni/following{/other_user}","gists_url":"https://api.github.com/users/YonatanGideoni/gists{/gist_id}","starred_url":"https://api.github.com/users/YonatanGideoni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/YonatanGideoni/subscriptions","organizations_url":"https://api.github.com/users/YonatanGideoni/orgs","repos_url":"https://api.github.com/users/YonatanGideoni/repos","events_url":"https://api.github.com/users/YonatanGideoni/events{/privacy}","received_events_url":"https://api.github.com/users/YonatanGideoni/received_events","type":"User","site_admin":false},"body":"Gives a loud fail and does not submit score if no team or match is selected, or if for some reason the score did not get to the server. Silent fail if signature is missing. Addresses the first part of issue #9.","created_at":"2018-07-22T09:13:18Z","updated_at":"2018-07-23T18:23:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"afd0dfbeb59bfad007622f8cd4a52a555fb4fab0","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23/commits","review_comments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23/comments","review_comment_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/23/comments","statuses_url":"https://api.github.com/repos/FirstLegoLeague/scoring/statuses/c5d773321e0f5a7878f48a6647badfc971e8bd42","head":{"label":"FirstLegoLeague:Server-validation","ref":"Server-validation","sha":"c5d773321e0f5a7878f48a6647badfc971e8bd42","user":{"login":"FirstLegoLeague","id":4487929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0ODc5Mjk=","avatar_url":"https://avatars3.githubusercontent.com/u/4487929?v=4","gravatar_id":"","url":"https://api.github.com/users/FirstLegoLeague","html_url":"https://github.com/FirstLegoLeague","followers_url":"https://api.github.com/users/FirstLegoLeague/followers","following_url":"https://api.github.com/users/FirstLegoLeague/following{/other_user}","gists_url":"https://api.github.com/users/FirstLegoLeague/gists{/gist_id}","starred_url":"https://api.github.com/users/FirstLegoLeague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FirstLegoLeague/subscriptions","organizations_url":"https://api.github.com/users/FirstLegoLeague/orgs","repos_url":"https://api.github.com/users/FirstLegoLeague/repos","events_url":"https://api.github.com/users/FirstLegoLeague/events{/privacy}","received_events_url":"https://api.github.com/users/FirstLegoLeague/received_events","type":"Organization","site_admin":false},"repo":{"id":137558748,"node_id":"MDEwOlJlcG9zaXRvcnkxMzc1NTg3NDg=","name":"scoring","full_name":"FirstLegoLeague/scoring","owner":{"login":"FirstLegoLeague","id":4487929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0ODc5Mjk=","avatar_url":"https://avatars3.githubusercontent.com/u/4487929?v=4","gravatar_id":"","url":"https://api.github.com/users/FirstLegoLeague","html_url":"https://github.com/FirstLegoLeague","followers_url":"https://api.github.com/users/FirstLegoLeague/followers","following_url":"https://api.github.com/users/FirstLegoLeague/following{/other_user}","gists_url":"https://api.github.com/users/FirstLegoLeague/gists{/gist_id}","starred_url":"https://api.github.com/users/FirstLegoLeague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FirstLegoLeague/subscriptions","organizations_url":"https://api.github.com/users/FirstLegoLeague/orgs","repos_url":"https://api.github.com/users/FirstLegoLeague/repos","events_url":"https://api.github.com/users/FirstLegoLeague/events{/privacy}","received_events_url":"https://api.github.com/users/FirstLegoLeague/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FirstLegoLeague/scoring","description":"FLL Scoresheet and scores managament","fork":false,"url":"https://api.github.com/repos/FirstLegoLeague/scoring","forks_url":"https://api.github.com/repos/FirstLegoLeague/scoring/forks","keys_url":"https://api.github.com/repos/FirstLegoLeague/scoring/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FirstLegoLeague/scoring/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FirstLegoLeague/scoring/teams","hooks_url":"https://api.github.com/repos/FirstLegoLeague/scoring/hooks","issue_events_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/events{/number}","events_url":"https://api.github.com/repos/FirstLegoLeague/scoring/events","assignees_url":"https://api.github.com/repos/FirstLegoLeague/scoring/assignees{/user}","branches_url":"https://api.github.com/repos/FirstLegoLeague/scoring/branches{/branch}","tags_url":"https://api.github.com/repos/FirstLegoLeague/scoring/tags","blobs_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/refs{/sha}","trees_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FirstLegoLeague/scoring/statuses/{sha}","languages_url":"https://api.github.com/repos/FirstLegoLeague/scoring/languages","stargazers_url":"https://api.github.com/repos/FirstLegoLeague/scoring/stargazers","contributors_url":"https://api.github.com/repos/FirstLegoLeague/scoring/contributors","subscribers_url":"https://api.github.com/repos/FirstLegoLeague/scoring/subscribers","subscription_url":"https://api.github.com/repos/FirstLegoLeague/scoring/subscription","commits_url":"https://api.github.com/repos/FirstLegoLeague/scoring/commits{/sha}","git_commits_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/commits{/sha}","comments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/comments{/number}","issue_comment_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/comments{/number}","contents_url":"https://api.github.com/repos/FirstLegoLeague/scoring/contents/{+path}","compare_url":"https://api.github.com/repos/FirstLegoLeague/scoring/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FirstLegoLeague/scoring/merges","archive_url":"https://api.github.com/repos/FirstLegoLeague/scoring/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FirstLegoLeague/scoring/downloads","issues_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues{/number}","pulls_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls{/number}","milestones_url":"https://api.github.com/repos/FirstLegoLeague/scoring/milestones{/number}","notifications_url":"https://api.github.com/repos/FirstLegoLeague/scoring/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FirstLegoLeague/scoring/labels{/name}","releases_url":"https://api.github.com/repos/FirstLegoLeague/scoring/releases{/id}","deployments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/deployments","created_at":"2018-06-16T06:25:25Z","updated_at":"2018-07-21T11:35:28Z","pushed_at":"2018-07-23T09:47:43Z","git_url":"git://github.com/FirstLegoLeague/scoring.git","ssh_url":"git@github.com:FirstLegoLeague/scoring.git","clone_url":"https://github.com/FirstLegoLeague/scoring.git","svn_url":"https://github.com/FirstLegoLeague/scoring","homepage":null,"size":57031,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":13,"license":null,"forks":1,"open_issues":13,"watchers":0,"default_branch":"master"}},"base":{"label":"FirstLegoLeague:master","ref":"master","sha":"647ef4d431c7df9a361270da0afaeaa53b9ce410","user":{"login":"FirstLegoLeague","id":4487929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0ODc5Mjk=","avatar_url":"https://avatars3.githubusercontent.com/u/4487929?v=4","gravatar_id":"","url":"https://api.github.com/users/FirstLegoLeague","html_url":"https://github.com/FirstLegoLeague","followers_url":"https://api.github.com/users/FirstLegoLeague/followers","following_url":"https://api.github.com/users/FirstLegoLeague/following{/other_user}","gists_url":"https://api.github.com/users/FirstLegoLeague/gists{/gist_id}","starred_url":"https://api.github.com/users/FirstLegoLeague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FirstLegoLeague/subscriptions","organizations_url":"https://api.github.com/users/FirstLegoLeague/orgs","repos_url":"https://api.github.com/users/FirstLegoLeague/repos","events_url":"https://api.github.com/users/FirstLegoLeague/events{/privacy}","received_events_url":"https://api.github.com/users/FirstLegoLeague/received_events","type":"Organization","site_admin":false},"repo":{"id":137558748,"node_id":"MDEwOlJlcG9zaXRvcnkxMzc1NTg3NDg=","name":"scoring","full_name":"FirstLegoLeague/scoring","owner":{"login":"FirstLegoLeague","id":4487929,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ0ODc5Mjk=","avatar_url":"https://avatars3.githubusercontent.com/u/4487929?v=4","gravatar_id":"","url":"https://api.github.com/users/FirstLegoLeague","html_url":"https://github.com/FirstLegoLeague","followers_url":"https://api.github.com/users/FirstLegoLeague/followers","following_url":"https://api.github.com/users/FirstLegoLeague/following{/other_user}","gists_url":"https://api.github.com/users/FirstLegoLeague/gists{/gist_id}","starred_url":"https://api.github.com/users/FirstLegoLeague/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FirstLegoLeague/subscriptions","organizations_url":"https://api.github.com/users/FirstLegoLeague/orgs","repos_url":"https://api.github.com/users/FirstLegoLeague/repos","events_url":"https://api.github.com/users/FirstLegoLeague/events{/privacy}","received_events_url":"https://api.github.com/users/FirstLegoLeague/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FirstLegoLeague/scoring","description":"FLL Scoresheet and scores managament","fork":false,"url":"https://api.github.com/repos/FirstLegoLeague/scoring","forks_url":"https://api.github.com/repos/FirstLegoLeague/scoring/forks","keys_url":"https://api.github.com/repos/FirstLegoLeague/scoring/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FirstLegoLeague/scoring/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FirstLegoLeague/scoring/teams","hooks_url":"https://api.github.com/repos/FirstLegoLeague/scoring/hooks","issue_events_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/events{/number}","events_url":"https://api.github.com/repos/FirstLegoLeague/scoring/events","assignees_url":"https://api.github.com/repos/FirstLegoLeague/scoring/assignees{/user}","branches_url":"https://api.github.com/repos/FirstLegoLeague/scoring/branches{/branch}","tags_url":"https://api.github.com/repos/FirstLegoLeague/scoring/tags","blobs_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/refs{/sha}","trees_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FirstLegoLeague/scoring/statuses/{sha}","languages_url":"https://api.github.com/repos/FirstLegoLeague/scoring/languages","stargazers_url":"https://api.github.com/repos/FirstLegoLeague/scoring/stargazers","contributors_url":"https://api.github.com/repos/FirstLegoLeague/scoring/contributors","subscribers_url":"https://api.github.com/repos/FirstLegoLeague/scoring/subscribers","subscription_url":"https://api.github.com/repos/FirstLegoLeague/scoring/subscription","commits_url":"https://api.github.com/repos/FirstLegoLeague/scoring/commits{/sha}","git_commits_url":"https://api.github.com/repos/FirstLegoLeague/scoring/git/commits{/sha}","comments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/comments{/number}","issue_comment_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/comments{/number}","contents_url":"https://api.github.com/repos/FirstLegoLeague/scoring/contents/{+path}","compare_url":"https://api.github.com/repos/FirstLegoLeague/scoring/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FirstLegoLeague/scoring/merges","archive_url":"https://api.github.com/repos/FirstLegoLeague/scoring/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FirstLegoLeague/scoring/downloads","issues_url":"https://api.github.com/repos/FirstLegoLeague/scoring/issues{/number}","pulls_url":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls{/number}","milestones_url":"https://api.github.com/repos/FirstLegoLeague/scoring/milestones{/number}","notifications_url":"https://api.github.com/repos/FirstLegoLeague/scoring/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FirstLegoLeague/scoring/labels{/name}","releases_url":"https://api.github.com/repos/FirstLegoLeague/scoring/releases{/id}","deployments_url":"https://api.github.com/repos/FirstLegoLeague/scoring/deployments","created_at":"2018-06-16T06:25:25Z","updated_at":"2018-07-21T11:35:28Z","pushed_at":"2018-07-23T09:47:43Z","git_url":"git://github.com/FirstLegoLeague/scoring.git","ssh_url":"git@github.com:FirstLegoLeague/scoring.git","clone_url":"https://github.com/FirstLegoLeague/scoring.git","svn_url":"https://github.com/FirstLegoLeague/scoring","homepage":null,"size":57031,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":13,"license":null,"forks":1,"open_issues":13,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23"},"html":{"href":"https://github.com/FirstLegoLeague/scoring/pull/23"},"issue":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/23"},"comments":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/FirstLegoLeague/scoring/statuses/c5d773321e0f5a7878f48a6647badfc971e8bd42"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"YonatanGideoni"}}