1.2.1 • Published 7 years ago

filter-query v1.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Filter Query img

This repository has the goal to transform a RESTFULL get filter as the following one

/api/v1/books?filter=created_at::>=2016-01-01|created_at::<2016-01-31

into an

const createQuery = require('filter-query').createQuery;

const filter = req.query.filter; // an express field const query = createQuery(filter);

// query = { // created_at: { // $gte: '2016-01-01', // $lt: '2016-01-31' // } // }

Books.find(query) .then(processBooks) .catch(handleError)

## You can use it as express middleware also;
```javascript
const buildQuery = require('filter-query').buildQuery;
const Router = require('express').Router;

Router.route('/api/v1/books')
  .get(buildQuery, getBooks);

function getBooks(req, res) {
  Books.find(req.query) // get the builded query from the middleware
    .then((books) => res.json(books))
    .catch(handleError);
}
1.2.1

7 years ago

1.1.1

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago