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

Update feathers-query-filters to version 2.0.0 πŸš€ #101

Merged
merged 2 commits into from
Jul 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"dependencies": {
"feathers-errors": "^2.0.1",
"feathers-query-filters": "^1.5.1",
"feathers-query-filters": "^2.0.0",
"lodash.omit": "^4.3.0",
"uberproto": "^1.2.0"
},
Expand Down
19 changes: 9 additions & 10 deletions src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class Service {
}

_find(params, count, getFilter = filter) {
const queryParams = params.query || {};
const filters = getFilter(queryParams);
const query = this.Model.find(queryParams).lean(this.lean);
const { filters, query } = getFilter(params.query || {});
const q = this.Model.find(query).lean(this.lean);

// $select uses a specific find syntax, so it has to come first.
if (filters.$select && filters.$select.length) {
Expand All @@ -40,31 +39,31 @@ class Service {
fields[key] = 1;
}

query.select(fields);
q.select(fields);
}

// Handle $sort
if (filters.$sort) {
query.sort(filters.$sort);
q.sort(filters.$sort);
}

// Handle $limit
if (filters.$limit) {
query.limit(filters.$limit);
q.limit(filters.$limit);
}

// Handle $skip
if (filters.$skip) {
query.skip(filters.$skip);
q.skip(filters.$skip);
}

// Handle $populate
if (filters.$populate){
query.populate(filters.$populate);
q.populate(filters.$populate);
}

const executeQuery = total => {
return query.exec().then(data => {
return q.exec().then(data => {
return {
total,
limit: filters.$limit,
Expand All @@ -75,7 +74,7 @@ class Service {
};

if(count) {
return this.Model.where(queryParams).count().exec().then(executeQuery);
return this.Model.where(query).count().exec().then(executeQuery);
}

return executeQuery();
Expand Down