Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to validate properly #38

Closed
farhan2106 opened this issue Feb 16, 2018 · 2 comments
Closed

Unable to validate properly #38

farhan2106 opened this issue Feb 16, 2018 · 2 comments

Comments

@farhan2106
Copy link

My Code:

// Controller
class UserController {
  async store ({ request }) {
    return { success: true }
  }
}

// Route
Route
  .post('/registration', 'UserController.store')
  .validator('UserRegistration')

// Validator
class UserRegistration {
  get rules () {
    return {
      email: 'required|email'
    }
  }

  get sanitizationRules () {
    // sanitize data before validation
    return {
      email: 'normalize_email'
    }
  }

  get formatter () {
    return 'jsonapi'
  }
}

Insomnia:

> POST /registration HTTP/1.1
> Host: localhost:3333
> User-Agent: insomnia/5.14.3
> Accept: application/json
> Content-Type: application/x-www-form-urlencoded
> Content-Length: 29
| email=sample.user%40gmail.com

< HTTP/1.1 400 Bad Request
< Content-Type: application/json; charset=utf-8
< Content-Length: 2
< Date: Fri, 16 Feb 2018 23:46:36 GMT
< Connection: keep-alive

Issue:
If I remove

  get formatter () {
    return 'jsonapi'
  }

I will receive 200. If I include the above, I receive 400.

@thetutlage
Copy link
Member

The formatter property returns the wrong value. Check the docs for upgrade guide https://adonisjs.com/docs/4.1/upgrade-guide#_formatters

@farhan2106
Copy link
Author

My bad 💃 .

Thank you for responding :D.

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants