Skip to content
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@
"lib": "lib"
},
"dependencies": {
"babel-polyfill": "^6.3.14",
"feathers-errors": "^2.0.1",
"feathers-query-filters": "^1.5.1",
"feathers-query-filters": "^2.0.0",
"is-plain-object": "^2.0.1",
"uberproto": "^1.2.0"
},
Expand Down
20 changes: 9 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
if(!global._babelPolyfill) { require('babel-polyfill'); }

import Proto from 'uberproto';
import filter from 'feathers-query-filters';
import isPlainObject from 'is-plain-object';
Expand Down Expand Up @@ -79,36 +77,36 @@ class Service {
}

_find(params, count, getFilter = filter) {
let query = this.db().select(['*']);
let filters = getFilter(params.query || {});
let q = this.db().select(['*']);
let { filters, query } = getFilter(params.query || {});

// $select uses a specific find syntax, so it has to come first.
if (filters.$select) {
let fields = filters.$select;
query = this.db().select(... fields);
q = this.db().select(... fields);
}

// build up the knex query out of the query params
this.knexify(query, params.query);
this.knexify(q, query);

// Handle $sort
if (filters.$sort) {
Object.keys(filters.$sort).forEach(key =>
query = query.orderBy(key, parseInt(filters.$sort[key], 10) === 1 ? 'asc' : 'desc'));
q = q.orderBy(key, parseInt(filters.$sort[key], 10) === 1 ? 'asc' : 'desc'));
}

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

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

const executeQuery = total => {
return query.then(data => {
return q.then(data => {
return {
total,
limit: filters.$limit,
Expand All @@ -121,7 +119,7 @@ class Service {
if(count) {
let countQuery = this.db().count(`${this.id} as total`);

this.knexify(countQuery, params.query);
this.knexify(countQuery, query);

return countQuery.then(count => count[0].total).then(executeQuery);
}
Expand Down