Skip to content

Commit

Permalink
req.body can be used to filter data on list and `show-many-relate…
Browse files Browse the repository at this point in the history
…d` routes
  • Loading branch information
webNeat committed May 19, 2018
1 parent baffdc2 commit 485cf45
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ Constructs a route that returns a list of the given model, then merges the `conv

- `GET /plural-of-model-name`
- The default converter returns only fields of basic types (`String`, `Number`, `Boolean`, `Buffer`, `Date`) and the `id` of the document. It ignores all `ObjectId`, `Object` and `Array` fields.
- Conditions on `req.body` will be used to filter the results.
- The offset parameter is set from query parameter `offset`, same for limit and sort parameters.
- Default values for offset and limit are `0` and `100` respectively. No sort is defined by default.

Expand Down Expand Up @@ -705,6 +706,8 @@ Returns an express router containing all [`resource`](#resource) routes of all g

# Development Notes

- **1.1.0**: Added [`extend`](#extend), [`login`](#login) and [`auth`](#auth).
- **1.2.0:** `req.body` is now used to filter results on `list` and `show-many-related` routes.

- **1.0.0**: A complete version is finally out!
- **1.1.0:** Added [`extend`](#extend), [`login`](#login) and [`auth`](#auth).

- **1.0.0:** A complete new version is finally out!
2 changes: 1 addition & 1 deletion src/routes/resource/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const list = (model, {converter, uri, actions} = {}) =>
onReadParams(setRoute('list')),
onQuery(setQuery(async req => ({
type: 'find',
conditions: {},
conditions: req.body || {},
projection: null,
options: {
skip: getOffset(req),
Expand Down
2 changes: 1 addition & 1 deletion src/routes/resource/show-related.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const showManyRelated = def('showManyRelated', {}, [T.MongooseModel, T.MongooseM
},
populate: [{
path: field,
match: {},
match: req.body || {},
select: null,
options: {
skip: getOffset(req),
Expand Down
5 changes: 4 additions & 1 deletion test/unit/resource/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ describe('Unit > Resource > list', () => {
assertRoute(list(User), {
method: 'get',
uri: '/users',
req: {
body: {name: 'Sasuke'}
},
query: {
type: 'find',
conditions: {},
conditions: {name: 'Sasuke'},
projection: null,
options: {
skip: 0,
Expand Down

0 comments on commit 485cf45

Please sign in to comment.