Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Add expandPaths option to en/disable options.as path expansion (#30)
Browse files Browse the repository at this point in the history
* Add `expandPaths` option

* Add `expandPaths` option

* Fix changes.
  • Loading branch information
jus101 authored and daffl committed Oct 11, 2017
1 parent 0223c28 commit 5931887
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/query-with-current-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import set from 'lodash.set';

const defaults = {
idField: '_id',
as: 'userId'
as: 'userId',
expandPaths: true
};

export default function (options = {}) {
Expand All @@ -28,6 +29,10 @@ export default function (options = {}) {
throw new Error(`Current user is missing '${options.idField}' field.`);
}

set(hook.params, `query.${options.as}`, id);
if (options.expandPaths) {
set(hook.params, `query.${options.as}`, id);
} else {
hook.params.query[options.as] = id;
}
};
}
6 changes: 4 additions & 2 deletions src/restrict-to-owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import queryWithCurrentUser from './query-with-current-user';

const defaults = {
idField: '_id',
ownerField: 'userId'
ownerField: 'userId',
expandPaths: true
};

export default function (options = {}) {
Expand All @@ -24,7 +25,8 @@ export default function (options = {}) {
if (hook.method === 'find' || hook.id === null) {
return queryWithCurrentUser({
idField: options.idField,
as: options.ownerField
as: options.ownerField,
expandPaths: options.expandPaths
})(hook);
}

Expand Down

0 comments on commit 5931887

Please sign in to comment.