{"action":"opened","issue":{"url":"https://api.github.com/repos/ctavan/express-validator/issues/168","labels_url":"https://api.github.com/repos/ctavan/express-validator/issues/168/labels{/name}","comments_url":"https://api.github.com/repos/ctavan/express-validator/issues/168/comments","events_url":"https://api.github.com/repos/ctavan/express-validator/issues/168/events","html_url":"https://github.com/ctavan/express-validator/issues/168","id":105025368,"number":168,"title":"Feature Request: Get subset of request data filtered by validation rules","user":{"login":"slavafomin","id":1702725,"avatar_url":"https://avatars.githubusercontent.com/u/1702725?v=3","gravatar_id":"","url":"https://api.github.com/users/slavafomin","html_url":"https://github.com/slavafomin","followers_url":"https://api.github.com/users/slavafomin/followers","following_url":"https://api.github.com/users/slavafomin/following{/other_user}","gists_url":"https://api.github.com/users/slavafomin/gists{/gist_id}","starred_url":"https://api.github.com/users/slavafomin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/slavafomin/subscriptions","organizations_url":"https://api.github.com/users/slavafomin/orgs","repos_url":"https://api.github.com/users/slavafomin/repos","events_url":"https://api.github.com/users/slavafomin/events{/privacy}","received_events_url":"https://api.github.com/users/slavafomin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-05T12:56:13Z","updated_at":"2015-09-05T12:56:13Z","closed_at":null,"body":"Hello!\r\n\r\nThank you for this great module. However, I'm looking for a way to get a subset of request data filtered by validation rules.\r\n\r\nI will give a small example:\r\n\r\n```javascript\r\n\r\n/** Imagine that this is the request body.\r\n{\r\n  firstName: 'Slava',\r\n  lastName: 'Fomin',\r\n  email: 's.fomin@betsol.ru',\r\n  password: 'some-pass-here',\r\n  someExtra: 'foo'\r\n}\r\n*/\r\n\r\n// I'm using this map to specify validation rules for the request.\r\nreq.checkBody({\r\n  firstName: {},\r\n  lastName: {},\r\n  email: {\r\n    notEmpty: {\r\n      errorMessage: 'Missing E-Mail'\r\n    },\r\n    isEmail: {\r\n      errorMessage: 'Incorrect E-Mail address'\r\n    }\r\n  }\r\n});\r\n\r\nvar errors = req.validationErrors(true);\r\nif (errors) {\r\n  return res.json(400, {\r\n    errors: errors\r\n  });\r\n}\r\n\r\nvar requestParams = req.getValidatedBody();\r\n\r\n// We are getting only parameters specified during the validation phase,\r\n// the extra request parameters, like \"password\", are ignored.\r\nconsole.log(requestParams);\r\n\r\n/**\r\n{\r\n  firstName: 'Slava',\r\n  lastName: 'Fomin',\r\n  email: 's.fomin@betsol.ru'\r\n}\r\n*/\r\n\r\n```\r\n\r\nThat way I will be able to use the entire object without the fear of overwriting some protected property later on (e.g. when updating user entity)."}}