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
Mongoose type "accessibleBy" returns an array of document after findOne #662
Comments
Just change the order of methods accessibleBy().findById() |
Works as expected |
Changing the order works with return this.catModel
.accessibleBy(ability, Action.Read)
.find(filters)
.exec()
// OK but triggers an error with return this.catModel
.accessibleBy(ability, Action.Update)
^^^^^^^^^^^^ // Error
.findById(id)
.exec() Property 'findById' does not exist on type 'QueryWithHelpers<(
Cat & Document<any, any, any> & { _id: ObjectId; })[],
Cat & Document<any, any, any> & { _id: ObjectId; },
AccessibleRecordQueryHelpers<Cat & Document<...> & { ...; }, {}, {}, {}>,
Cat & ... 1 more ... & { ...; }>'. Model injected by NestJS with private catModel: AccessibleRecordModel<CatDocument> |
Ah OK, there is no |
I have the same problem, @gterras do you found a fix ? |
I opened an issue at mongoose Automattic/mongoose#12286 As a workaround you can use any |
FYI this has been fixed in mongoose Automattic/mongoose#12309 |
Awesome! Thanks for pushing this! |
Does the problem exist with every
If I change the order (e.g. package.json "@casl/ability": "^6.3.0",
"@casl/mongoose": "^7.1.0",
"mongoose": "^6.6.4", |
Does it work if you do |
@stalniy Unfortunately no.
|
The |
@stalniy Should we reopen the issue? |
looks like it's not a casl issue but mongoose one. Types say this method exists but when I run: Post.find().findByIdAndDelete(); I get |
|
|
@gterras The problem is not the type, see #662 (comment) and #662 (comment). |
@danielbayerlein do you have suggestion how to fix this? Because this is how mongoose types designed, for example Want many use If you know how to make types work, so that they can rely on prev constructs, then awesome, let's fix this because I think it's impossible in how mongoose currently defines its types |
|
Explained just above:
|
Model.accessibleBy
from@casl/mongoose
returns an array of document which makes it hard to deal with with operations such asfindById
and following:Update operations after find one (is there a better way to check ability before update?) trigger an error since it expects an array:
The text was updated successfully, but these errors were encountered: