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

Fix restaurant endpoitns to support slugs as ids #2075

Open
L8D opened this issue Dec 17, 2015 · 2 comments
Open

Fix restaurant endpoitns to support slugs as ids #2075

L8D opened this issue Dec 17, 2015 · 2 comments
Assignees

Comments

@L8D
Copy link
Member

L8D commented Dec 17, 2015

This would require replacing all the dirac calls with controller methods (at least all the reads)

@L8D L8D self-assigned this Dec 17, 2015
@jrf0110
Copy link
Member

jrf0110 commented Dec 17, 2015

If you wanted to continue using dirac-middleware, some simple middleware could support slugs:

module.exports = ( options )=>{
  options = utils.defaults( options || {}, {
    idParam: 'id'
  });

  return ( req, res, next )=>{
    var id = req.params[ options.idParam ];

    if ( isNaN( +id ) ){
      req.queryObj.text_id = id;
    } else {
      req.queryObj.id = id;
    }

    return next();
  };
};

Or you could just use the .getRestaurant() middleware to fetch the restaurant, which already supports fetching by slug

@jrf0110
Copy link
Member

jrf0110 commented Dec 17, 2015

And of course, that could be generalized further

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