{"action":"created","comment":{"url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/comments/169160303","pull_request_review_id":97639332,"id":169160303,"diff_hunk":"@@ -31,7 +41,40 @@ const resolvers = {\n         )\n       }\n \n-      let query = createQuery(forwardSortationArea, filter)\n+      let query = {\n+        $and: [\n+          {\n+            forwardSortationArea,\n+          },\n+        ],\n+      }\n+\n+      if (filter) {\n+        for (let key in filter) {\n+          // make sure the key exists in the comparators' keys\n+          if (Object.keys(comparators).includes(key)) {\n+            // if the value is a number\n+            // - optionally starting with a minus sign\n+            // - containing zero or one decimal places\n+            // convert it to a float instead of a string\n+            if (filter[key].match(/^-?\\d+\\.?\\d+$/)) {\n+              filter[key] = parseFloat(filter[key])\n+            }\n+\n+            // We are evaling our own code here, not user input.\n+            // Filter.field is our code, stringified and stored in an enum.\n+            // The user choses one of the enum values and we convert the string\n+            // back to a function which accepts a matcher and generates the\n+            // query we need to find that field.\n+            // eslint-disable-next-line no-eval\n+            let queryGenerator = eval(filter.field)\n+            let attrQuery = queryGenerator({\n+              [comparators[key]]: filter[key],\n+            })\n+            query['$and'].push(attrQuery)","path":"api/src/schema/resolvers.js","position":61,"original_position":61,"commit_id":"78d3881ece49365a6efc243fe071c8eb3acf98f4","original_commit_id":"78d3881ece49365a6efc243fe071c8eb3acf98f4","user":{"login":"pcraig3","id":2454380,"avatar_url":"https://avatars1.githubusercontent.com/u/2454380?v=4","gravatar_id":"","url":"https://api.github.com/users/pcraig3","html_url":"https://github.com/pcraig3","followers_url":"https://api.github.com/users/pcraig3/followers","following_url":"https://api.github.com/users/pcraig3/following{/other_user}","gists_url":"https://api.github.com/users/pcraig3/gists{/gist_id}","starred_url":"https://api.github.com/users/pcraig3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pcraig3/subscriptions","organizations_url":"https://api.github.com/users/pcraig3/orgs","repos_url":"https://api.github.com/users/pcraig3/repos","events_url":"https://api.github.com/users/pcraig3/events{/privacy}","received_events_url":"https://api.github.com/users/pcraig3/received_events","type":"User","site_admin":false},"body":"Looks really clean though, eh? I know we normally frown on `eval`s, but I think this is pretty neat.","created_at":"2018-02-19T19:49:23Z","updated_at":"2018-02-19T19:57:07Z","html_url":"https://github.com/cds-snc/nrcan_api/pull/204#discussion_r169160303","pull_request_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/comments/169160303"},"html":{"href":"https://github.com/cds-snc/nrcan_api/pull/204#discussion_r169160303"},"pull_request":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204"}}},"pull_request":{"url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204","id":169851780,"html_url":"https://github.com/cds-snc/nrcan_api/pull/204","diff_url":"https://github.com/cds-snc/nrcan_api/pull/204.diff","patch_url":"https://github.com/cds-snc/nrcan_api/pull/204.patch","issue_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/204","number":204,"state":"open","locked":false,"title":"Filter on nested documents","user":{"login":"sleepycat","id":109692,"avatar_url":"https://avatars0.githubusercontent.com/u/109692?v=4","gravatar_id":"","url":"https://api.github.com/users/sleepycat","html_url":"https://github.com/sleepycat","followers_url":"https://api.github.com/users/sleepycat/followers","following_url":"https://api.github.com/users/sleepycat/following{/other_user}","gists_url":"https://api.github.com/users/sleepycat/gists{/gist_id}","starred_url":"https://api.github.com/users/sleepycat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sleepycat/subscriptions","organizations_url":"https://api.github.com/users/sleepycat/orgs","repos_url":"https://api.github.com/users/sleepycat/repos","events_url":"https://api.github.com/users/sleepycat/events{/privacy}","received_events_url":"https://api.github.com/users/sleepycat/received_events","type":"User","site_admin":false},"body":"This is the groundwork needed for supporting filters on arbitrary\r\nfields. This also sets us up for painlessly supporting multiple filters.","created_at":"2018-02-18T21:47:31Z","updated_at":"2018-02-19T19:57:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ee8fe7284739aba0a837a349bc05f57188c5ff93","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204/commits","review_comments_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204/comments","review_comment_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/204/comments","statuses_url":"https://api.github.com/repos/cds-snc/nrcan_api/statuses/78d3881ece49365a6efc243fe071c8eb3acf98f4","head":{"label":"cds-snc:filter_on_nested_attributes","ref":"filter_on_nested_attributes","sha":"78d3881ece49365a6efc243fe071c8eb3acf98f4","user":{"login":"cds-snc","id":30166251,"avatar_url":"https://avatars1.githubusercontent.com/u/30166251?v=4","gravatar_id":"","url":"https://api.github.com/users/cds-snc","html_url":"https://github.com/cds-snc","followers_url":"https://api.github.com/users/cds-snc/followers","following_url":"https://api.github.com/users/cds-snc/following{/other_user}","gists_url":"https://api.github.com/users/cds-snc/gists{/gist_id}","starred_url":"https://api.github.com/users/cds-snc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cds-snc/subscriptions","organizations_url":"https://api.github.com/users/cds-snc/orgs","repos_url":"https://api.github.com/users/cds-snc/repos","events_url":"https://api.github.com/users/cds-snc/events{/privacy}","received_events_url":"https://api.github.com/users/cds-snc/received_events","type":"Organization","site_admin":false},"repo":{"id":111843247,"name":"nrcan_api","full_name":"cds-snc/nrcan_api","owner":{"login":"cds-snc","id":30166251,"avatar_url":"https://avatars1.githubusercontent.com/u/30166251?v=4","gravatar_id":"","url":"https://api.github.com/users/cds-snc","html_url":"https://github.com/cds-snc","followers_url":"https://api.github.com/users/cds-snc/followers","following_url":"https://api.github.com/users/cds-snc/following{/other_user}","gists_url":"https://api.github.com/users/cds-snc/gists{/gist_id}","starred_url":"https://api.github.com/users/cds-snc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cds-snc/subscriptions","organizations_url":"https://api.github.com/users/cds-snc/orgs","repos_url":"https://api.github.com/users/cds-snc/repos","events_url":"https://api.github.com/users/cds-snc/events{/privacy}","received_events_url":"https://api.github.com/users/cds-snc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cds-snc/nrcan_api","description":"An API for Natural Resources Canada's Energuide data.","fork":false,"url":"https://api.github.com/repos/cds-snc/nrcan_api","forks_url":"https://api.github.com/repos/cds-snc/nrcan_api/forks","keys_url":"https://api.github.com/repos/cds-snc/nrcan_api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cds-snc/nrcan_api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cds-snc/nrcan_api/teams","hooks_url":"https://api.github.com/repos/cds-snc/nrcan_api/hooks","issue_events_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/events{/number}","events_url":"https://api.github.com/repos/cds-snc/nrcan_api/events","assignees_url":"https://api.github.com/repos/cds-snc/nrcan_api/assignees{/user}","branches_url":"https://api.github.com/repos/cds-snc/nrcan_api/branches{/branch}","tags_url":"https://api.github.com/repos/cds-snc/nrcan_api/tags","blobs_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/refs{/sha}","trees_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cds-snc/nrcan_api/statuses/{sha}","languages_url":"https://api.github.com/repos/cds-snc/nrcan_api/languages","stargazers_url":"https://api.github.com/repos/cds-snc/nrcan_api/stargazers","contributors_url":"https://api.github.com/repos/cds-snc/nrcan_api/contributors","subscribers_url":"https://api.github.com/repos/cds-snc/nrcan_api/subscribers","subscription_url":"https://api.github.com/repos/cds-snc/nrcan_api/subscription","commits_url":"https://api.github.com/repos/cds-snc/nrcan_api/commits{/sha}","git_commits_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/commits{/sha}","comments_url":"https://api.github.com/repos/cds-snc/nrcan_api/comments{/number}","issue_comment_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/comments{/number}","contents_url":"https://api.github.com/repos/cds-snc/nrcan_api/contents/{+path}","compare_url":"https://api.github.com/repos/cds-snc/nrcan_api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cds-snc/nrcan_api/merges","archive_url":"https://api.github.com/repos/cds-snc/nrcan_api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cds-snc/nrcan_api/downloads","issues_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues{/number}","pulls_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls{/number}","milestones_url":"https://api.github.com/repos/cds-snc/nrcan_api/milestones{/number}","notifications_url":"https://api.github.com/repos/cds-snc/nrcan_api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cds-snc/nrcan_api/labels{/name}","releases_url":"https://api.github.com/repos/cds-snc/nrcan_api/releases{/id}","deployments_url":"https://api.github.com/repos/cds-snc/nrcan_api/deployments","created_at":"2017-11-23T19:19:13Z","updated_at":"2018-02-06T16:20:44Z","pushed_at":"2018-02-19T19:54:22Z","git_url":"git://github.com/cds-snc/nrcan_api.git","ssh_url":"git@github.com:cds-snc/nrcan_api.git","clone_url":"https://github.com/cds-snc/nrcan_api.git","svn_url":"https://github.com/cds-snc/nrcan_api","homepage":null,"size":1231,"stargazers_count":2,"watchers_count":2,"language":"Python","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":9,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":9,"watchers":2,"default_branch":"master"}},"base":{"label":"cds-snc:master","ref":"master","sha":"0e12ed8bd9b5a4f13ae5dacdb63bcf8e5c335735","user":{"login":"cds-snc","id":30166251,"avatar_url":"https://avatars1.githubusercontent.com/u/30166251?v=4","gravatar_id":"","url":"https://api.github.com/users/cds-snc","html_url":"https://github.com/cds-snc","followers_url":"https://api.github.com/users/cds-snc/followers","following_url":"https://api.github.com/users/cds-snc/following{/other_user}","gists_url":"https://api.github.com/users/cds-snc/gists{/gist_id}","starred_url":"https://api.github.com/users/cds-snc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cds-snc/subscriptions","organizations_url":"https://api.github.com/users/cds-snc/orgs","repos_url":"https://api.github.com/users/cds-snc/repos","events_url":"https://api.github.com/users/cds-snc/events{/privacy}","received_events_url":"https://api.github.com/users/cds-snc/received_events","type":"Organization","site_admin":false},"repo":{"id":111843247,"name":"nrcan_api","full_name":"cds-snc/nrcan_api","owner":{"login":"cds-snc","id":30166251,"avatar_url":"https://avatars1.githubusercontent.com/u/30166251?v=4","gravatar_id":"","url":"https://api.github.com/users/cds-snc","html_url":"https://github.com/cds-snc","followers_url":"https://api.github.com/users/cds-snc/followers","following_url":"https://api.github.com/users/cds-snc/following{/other_user}","gists_url":"https://api.github.com/users/cds-snc/gists{/gist_id}","starred_url":"https://api.github.com/users/cds-snc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cds-snc/subscriptions","organizations_url":"https://api.github.com/users/cds-snc/orgs","repos_url":"https://api.github.com/users/cds-snc/repos","events_url":"https://api.github.com/users/cds-snc/events{/privacy}","received_events_url":"https://api.github.com/users/cds-snc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cds-snc/nrcan_api","description":"An API for Natural Resources Canada's Energuide data.","fork":false,"url":"https://api.github.com/repos/cds-snc/nrcan_api","forks_url":"https://api.github.com/repos/cds-snc/nrcan_api/forks","keys_url":"https://api.github.com/repos/cds-snc/nrcan_api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cds-snc/nrcan_api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cds-snc/nrcan_api/teams","hooks_url":"https://api.github.com/repos/cds-snc/nrcan_api/hooks","issue_events_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/events{/number}","events_url":"https://api.github.com/repos/cds-snc/nrcan_api/events","assignees_url":"https://api.github.com/repos/cds-snc/nrcan_api/assignees{/user}","branches_url":"https://api.github.com/repos/cds-snc/nrcan_api/branches{/branch}","tags_url":"https://api.github.com/repos/cds-snc/nrcan_api/tags","blobs_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/refs{/sha}","trees_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cds-snc/nrcan_api/statuses/{sha}","languages_url":"https://api.github.com/repos/cds-snc/nrcan_api/languages","stargazers_url":"https://api.github.com/repos/cds-snc/nrcan_api/stargazers","contributors_url":"https://api.github.com/repos/cds-snc/nrcan_api/contributors","subscribers_url":"https://api.github.com/repos/cds-snc/nrcan_api/subscribers","subscription_url":"https://api.github.com/repos/cds-snc/nrcan_api/subscription","commits_url":"https://api.github.com/repos/cds-snc/nrcan_api/commits{/sha}","git_commits_url":"https://api.github.com/repos/cds-snc/nrcan_api/git/commits{/sha}","comments_url":"https://api.github.com/repos/cds-snc/nrcan_api/comments{/number}","issue_comment_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues/comments{/number}","contents_url":"https://api.github.com/repos/cds-snc/nrcan_api/contents/{+path}","compare_url":"https://api.github.com/repos/cds-snc/nrcan_api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cds-snc/nrcan_api/merges","archive_url":"https://api.github.com/repos/cds-snc/nrcan_api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cds-snc/nrcan_api/downloads","issues_url":"https://api.github.com/repos/cds-snc/nrcan_api/issues{/number}","pulls_url":"https://api.github.com/repos/cds-snc/nrcan_api/pulls{/number}","milestones_url":"https://api.github.com/repos/cds-snc/nrcan_api/milestones{/number}","notifications_url":"https://api.github.com/repos/cds-snc/nrcan_api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cds-snc/nrcan_api/labels{/name}","releases_url":"https://api.github.com/repos/cds-snc/nrcan_api/releases{/id}","deployments_url":"https://api.github.com/repos/cds-snc/nrcan_api/deployments","created_at":"2017-11-23T19:19:13Z","updated_at":"2018-02-06T16:20:44Z","pushed_at":"2018-02-19T19:54:22Z","git_url":"git://github.com/cds-snc/nrcan_api.git","ssh_url":"git@github.com:cds-snc/nrcan_api.git","clone_url":"https://github.com/cds-snc/nrcan_api.git","svn_url":"https://github.com/cds-snc/nrcan_api","homepage":null,"size":1231,"stargazers_count":2,"watchers_count":2,"language":"Python","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":9,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":9,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204"},"html":{"href":"https://github.com/cds-snc/nrcan_api/pull/204"},"issue":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/issues/204"},"comments":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/issues/204/comments"},"review_comments":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204/comments"},"review_comment":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/pulls/204/commits"},"statuses":{"href":"https://api.github.com/repos/cds-snc/nrcan_api/statuses/78d3881ece49365a6efc243fe071c8eb3acf98f4"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"pcraig3"}}