trailsjs / trailpack-express

:package: Express Trailpack
MIT License
12 stars 15 forks source link

Find policy for query string #40

Closed gutenye closed 8 years ago

gutenye commented 8 years ago

In https://github.com/trailsjs/trailpack-express/blob/master/api/policies/FootprintPolicy.js#L34

  find(req, res, next) {
    if (req.params.id && !_.isEmpty(req.query)) {
      return res.boom.preconditionFailed(this.__('errors.footprints.find.mutex'))
    }

    next()
  }

Got an error in following example

GET /users/1?populate=posts

This request should be valid

jaumard commented 8 years ago

Hi @gutenye what's the error ? Also what is your config/footprints.js configuration ?

gutenye commented 8 years ago

The error is

GET /users/1?populate=posts

HTTP/1.1 412 Precondition Failed
{
    "error": "Precondition Failed",
    "message": "errors.footprints.find.mutex",
    "statusCode": 412
}

My config/footprints.js is https://gist.github.com/gutenye/41ac7f96e9b01c87d12652f989aedde2

jaumard commented 8 years ago

Hum can you test with a prefix ? Maybe there a problem when there no prefix, I never had a problem like this before the only difference is that I use a prefix.

Also if your model is called User you should call /user/1?populate=posts instead, I think plural are not supported yet.

gutenye commented 8 years ago

With prefix, it works without an error.

What is this file https://github.com/trailsjs/trailpack-express/blob/master/api/policies/FootprintPolicy.js#L34 for?

EDIT: with prefix, it is still not working.

jaumard commented 8 years ago

@gutenye ho I see the problem you're right we should test if criteria is not empty and not query ! I'll fix this soon! I can replicate your problem it work great with or without prefix for me if I didn't set ?populate=post but once I set it I have the 412 error.

jaumard commented 8 years ago

@gutenye I just create a PR with the fix, can you test it and let me know if it's fix your problem ? Normally it should.

Thanks