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

Make sure ids in queries are respected #294

Merged
merged 3 commits into from
Jan 13, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Service extends AdapterService {
_get (id, params = {}) {
const { query, filters } = this.filterQuery(params);

query[this.id] = id;
query.$and = (query.$and || []).concat([{ [this.id]: id }]);

const discriminator = query[this.discriminatorKey] || this.discriminatorKey;
const model = this.discriminators[discriminator] || this.Model;
Expand Down Expand Up @@ -186,7 +186,7 @@ class Service extends AdapterService {
setDefaultsOnInsert: true
}, params.mongoose);

query[this.id] = id;
query.$and = (query.$and || []).concat({ [this.id]: id });

if (this.id === '_id') {
// We can not update default mongo ids
Expand Down Expand Up @@ -243,7 +243,7 @@ class Service extends AdapterService {
}, params.mongoose);

if (id !== null) {
query[this.id] = id;
query.$and = (query.$and || []).concat({ [this.id]: id });
}

if (this.id === '_id') {
Expand Down Expand Up @@ -298,7 +298,7 @@ class Service extends AdapterService {
}

if (id !== null) {
query[this.id] = id;
query.$and = (query.$and || []).concat({ [this.id]: id });

return this.Model.findOneAndDelete(query, params.mongoose).lean(this.lean)
.exec().then(result => {
Expand Down
24 changes: 20 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@
"mongoose": "^5.3.14"
},
"dependencies": {
"@feathersjs/adapter-commons": "^1.0.4",
"@feathersjs/adapter-commons": "^2.0.0",
"@feathersjs/commons": "^4.0.0",
"@feathersjs/errors": "^3.3.5"
},
"devDependencies": {
"@feathersjs/adapter-tests": "^1.0.1",
"@feathersjs/express": "^1.3.0",
"@feathersjs/feathers": "^3.3.0",
"@feathersjs/socketio": "^3.2.8",
Expand Down
8 changes: 6 additions & 2 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const mongoose = require('mongoose');

const errors = require('@feathersjs/errors');
const feathers = require('@feathersjs/feathers');
const adaptersTests = require('@feathersjs/adapter-commons/tests');
const adaptersTests = require('@feathersjs/adapter-tests');

const adapter = require('../lib');
const testSuite = adaptersTests([
Expand Down Expand Up @@ -65,7 +65,11 @@ const testSuite = adaptersTests([
'.find + paginate',
'.find + paginate + $limit + $skip',
'.find + paginate + $limit 0',
'.find + paginate + params'
'.find + paginate + params',
'.get + id + query id',
'.remove + id + query id',
'.update + id + query id',
'.patch + id + query id'
]);

const {
Expand Down