You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to add a before hook on the list action that can pre filter my list of records depending on an array.
In the following example I want to pre filter the list of users depending on if their id is in a list of ids. I'm using fastify as a server and typeORM for my database.
the '$in' operator seems not to be supported and always returns error like 'Cannot read properties of undefined (reading 'type')'
I also tried to do custom filter but there is no way to actual create a new Filter and use it inside adminJS hook function.
There is a similar issue opened with no response : #1564
"res":{"statusCode":500},"err":{"type":"TypeError","message":"Cannot read properties of undefined (reading 'type')","stack":"TypeError: Cannot read properties of undefined (reading 'type')\n at Object.isParserForType (file://node_modules/@adminjs/typeorm/lib/utils/filter/date-filter.parser.js:3:80)\n at file://node_modules/@adminjs/typeorm/lib/utils/filter/filter.converter.js:10:46\n at Array.find (<anonymous>)\n at file://node_modules/@adminjs/typeorm/lib/utils/filter/filter.converter.js:10:32\n at Array.forEach (<anonymous>)\n at convertFilter (file://node_modules/@adminjs/typeorm/lib/utils/filter/filter.converter.js:9:35)\n at Resource.find (file://node_modules/@adminjs/typeorm/lib/Resource.js:48:20)\n at Object.handler (file://node_modules/adminjs/lib/backend/actions/list/list-action.js:66:36)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"},"msg":"Cannot read properties of undefined (reading 'type')"}
Relevant code that's giving you issues
exportconstfilter=async(request: ActionRequest,context: ActionContext)=>{const{ query ={}}=request;const{ currentAdmin }=context;// If the current user is admin, do not filterif(currentAdmin.role===Role.Admin){returnrequest;}else{// For non-admin users, find associated centersconstuserRepository=datasource.getRepository(User);constconnectedUser=awaituserRepository.findOne({where: {email: currentAdmin.email},});if(connectedUser){constprescriptionIds=['id1','id2','id3'];constnewQuery={
...query,filters: {
...query.filters,id: {$in: prescriptionIds},// <--- Here is the problem},};request.query=newQuery;returnrequest;}}};
The text was updated successfully, but these errors were encountered:
Not pretty but you can override the find method called on the resource to bypass the whole unflatten/flatten filter mechanism. It is specific to typeorm:
Contact Details
No response
What happened?
I want to add a before hook on the list action that can pre filter my list of records depending on an array.
In the following example I want to pre filter the list of users depending on if their id is in a list of ids.
I'm using fastify as a server and typeORM for my database.
the '$in' operator seems not to be supported and always returns error like 'Cannot read properties of undefined (reading 'type')'
I also tried to do custom filter but there is no way to actual create a new Filter and use it inside adminJS hook function.
There is a similar issue opened with no response : #1564
Bug prevalence
Whenever I want to load the list of users
AdminJS dependencies version
What browsers do you see the problem on?
Chrome
Relevant log output
Relevant code that's giving you issues
The text was updated successfully, but these errors were encountered: