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

Add options to find query #14

Merged
merged 1 commit into from
Feb 2, 2016
Merged
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
20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ class Service {
extend(obj) {
return Proto.extend(obj, this);
}

_find(params, getFilter = filter) {
let where = utils.getWhere(params.query);
let filters = getFilter(where);
let order = utils.getOrder(filters.$sort);
let query = {
let query = Object.assign({
where, order,
limit: filters.$limit,
offset: filters.$skip,
attributes: filters.$select || null
};
}, params.sequelize);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 can we put this under $sequelize instead? That way it follows a similar pattern to the other special query params?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's ok. It's part of params not params.query (where we use that pattern to somewhat avoid property name clashes).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right. My bad. ok let's :shipit:


return this.Model.findAndCount(query).then(result => {
return {
total: result.count,
Expand All @@ -47,14 +47,14 @@ class Service {

find(params) {
const result = this._find(params, where => filter(where, this.paginate));

if(!this.paginate.default) {
return result.then(page => page.data);
}

return result;
}

_get(id) {
return this.Model.findById(id).then(instance => {
if(!instance) {
Expand All @@ -65,17 +65,17 @@ class Service {
})
.catch(utils.errorHandler);
}

// returns either the model intance for an id or all unpaginated
// items for `params` if id is null
_getOrFind(id, params) {
if(id === null) {
return this._find(params).then(page => page.data);
}

return this._get(id, params);
}

get(id, params) {
return this._get(id, params);
}
Expand Down