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

Feature Request: Implement the options.filter with support for async/promises #39

Open
kolbma opened this issue Apr 3, 2017 · 0 comments

Comments

@kolbma
Copy link
Contributor

kolbma commented Apr 3, 2017

I don't have the data for the filter in request or response.
There is needed a mongoose query to get this data.
These queries are always async. So I get the result only in a callback or via promise.

No way to return a complete object by the called function:
https://github.com/saintedlama/restify-mongoose/blob/master/index.js#L267
query.where(self.options.filter(req, res));

I've to write a lot of code to get this to work...

This is TypeScript:

function createBookController(req: restify.Request): Promise<restifyMongoose> {
  return controlHelper.dependRequestUser(req)
    .then((user) => {
      const filterobj = { _creator: user._id };
      return createDynfilterFn(filterobj);
    })
    .then((dynfilter) => {
      const bookController = restifyMongoose(Book, {
        filter: dynfilter,
        listProjection: listProjection,
        detailProjection: detailProjection
      });
      log.debug('Created bookController with filter ' + JSON.stringify(dynfilter(undefined, undefined)));
      return bookController;
    });
}

export function query(req: restify.Request, res: restify.Response, next: restify.Next) {
  createBookController(req).then((bookController: restifyMongoose) => {
    bookController.query()(req, res, next);
  });
}

function createDynfilterFn(filterobj: Object): Function {
  const obj = filterobj;
  return (request: restify.Request, response: restify.Response) => {
    return obj;
  };
}

So it would be quite handy if I could give a promise to the filter option.
Or is there another solution?

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

1 participant