SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.15k stars 659 forks source link

[Bug]: Issue with findMany Query Filtering in AdminJS with Prisma #1569

Closed mc-arenas closed 11 months ago

mc-arenas commented 11 months ago

Contact Details

No response

What happened?

Hello,

I'm facing an issue while trying to filter records using a findMany query in an AdminJS action handler. I'm using Prisma as my ORM. Here's a snippet of my code:

const {userId} = request.payload ? request.payload['userId'].trim() : '0';
const transactions = await prisma.legacyTransaction.findMany({
  where: {
    user_id: Number(userId)
  }
});

When I run this code, I encounter the following error: PrismaClientValidationError: Argument equals is missing. I tried modifying the query to include equals like so:

const transactions = await prisma.legacyTransaction.findMany({
  where: {
    user_id: {
      equals: Number(userId)
    }
  }
});

However, the error persists. The user_id field is defined as Int in my schema.prisma. I'm wondering if there's something with AdminJS that might be causing this issue or if it's a Prisma-related matter. Any insights or suggestions would be greatly appreciated.

Thank you!

Bug prevalence

always

AdminJS dependencies version

"dependencies": {
    "@adminjs/express": "~6.0.1",
    "@adminjs/import-export": "~3.0.0",
    "@adminjs/logger": "~5.0.1",
    "@adminjs/prisma": "4.0.0",
    "@adminjs/themes": "~1.0.1",
    "@paralleldrive/cuid2": "~2.2.2",
    "@types/uuid": "~9.0.4",
    "adminjs": "~7.2.2",
    "argon2": "~0.31.1",
    "cors": "~2.8.5",
    "env-var": "~7.4.1",
    "express": "~4.18.2",
    "express-session": "~1.17.3",
    "helmet": "~7.0.0",
    "libphonenumber-js": "~1.10.44",
    "tslib": "~2.6.2",
    "uuid": "~9.0.1",
    "react": "~17.0.0",
    "react-dom": "~17.0.0",
    "@adminjs/design-system": "~4.0.3",
    "axios": "~1.5.1",
    "fast-csv": "~4.3.6"
  },

What browsers do you see the problem on?

No response

Relevant log output

No response

Relevant code that's giving you issues

No response

dziraf commented 11 months ago

Your code is incorrect:

const {userId} = request.payload ? request.payload['userId'].trim() : '0';

you're destructuring userId property from a string instead of an object. It should work if you remove curly brackets.