Skip to content

Commit

Permalink
Make sure ids in queries are respected
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 12, 2019
1 parent cf286b4 commit f7e023d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
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
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"@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

0 comments on commit f7e023d

Please sign in to comment.