Skip to content
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

[Bug]: API Products - order (sort) by status capacity AND $or query on products #10572

Open
dooke opened this issue Dec 12, 2024 · 3 comments
Open

Comments

@dooke
Copy link

dooke commented Dec 12, 2024

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "^2.1.1",
    "@medusajs/cli": "^2.1.1",
    "@medusajs/framework": "^2.1.1",
    "@medusajs/medusa": "^2.1.1",
    "@medusajs/payment-stripe": "^2.1.1",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@sendgrid/mail": "^8.1.4",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "^2.1.1",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v20.17.0

Database and its version

PostGresSQL 13

Operating system name and version

Mac Os

Browser name

Brave/Chrome

What happended?

  1. PRODUCTS SORTING
    --
    OK -> Results are sorted by id
    curl --location 'http://localhost:9000/admin/products?limit=2&fields=title%2Cstatus&order=-id' \ --header 'Authorization: Bearer xxxx' \ --data ''
    Response: Products sorted

NOT OK -> Results aren't sorted by status (draft, published etc.)
curl --location 'http://localhost:9000/admin/products?limit=2&fields=title%2Cstatus&order=-status' \ --header 'Authorization: Bearer xxxx' \ --data ''
curl --location 'http://localhost:9000/admin/products?limit=2&fields=title%2Cstatus&order=status' \ --header 'Authorization: Bearer xxxx' \ --data ''
Response: Products NOT sorted (no matter "-" sign )

  1. PRODUCTS SEARCHING
    --
    NOT OK -> (syntax 1)
    Postman params passed:
    $or[]:{"title":"shirt"}
    $or[]:{"q":"shirt"}
    curl --location 'http://localhost:9000/admin/products?%24or[]={%22title%22%3A%22shirt%22}&%24or[]={%22q%22%3A%22shirt%22}' \ --header 'Authorization: Bearer xxxx' \ --data ''

NOT OK -> (syntax 2)
Postman params passed:
$or[]:{"title":"shirt"},{"q":"shirt"}
curl --location 'http://localhost:9000/admin/products?%24or[]={%22title%22%3A%22shirt%22}%2C{%22q%22%3A%22shirt%22}' \ --header 'Authorization: Bearer xxxx' \ --data ''

Both response are:
http: GET /admin/products?limit=2&fields=title&$or[]="title":"shirt","q":"shirt" ← - (400) - 5.119 ms
error: Invalid request: Expected type: 'object' for field '$or, 0', got: 'string'; Expected type: 'object' for field '$or, 1', got: 'string'

For this second query using $or maybe my syntax is incorrect but tried a multiple

Expected behavior

  1. PRODUCTS SORTING
  • Sorting by ID -> OK
  • Sorting by status -> NOT OK
  1. PRODUCTS SEARCHING
  • A result without error.

Actual behavior

  1. PRODUCTS SORTING
  • Sorting only by ID is possible
  1. PRODUCTS SEARCHING
    http: GET /admin/products?limit=2&fields=title&$or[]="title":"shirt","q":"shirt" ← - (400) - 5.119 ms
    error: Invalid request: Expected type: 'object' for field '$or, 0', got: 'string'; Expected type: 'object' for field '$or, 1', got: 'string'

Link to reproduction repo

http://localhost:9000

@abdebot
Copy link

abdebot commented Dec 17, 2024

i have the same bug !

@JaySPatel2962
Copy link

JaySPatel2962 commented Dec 19, 2024

I am experiencing the same issue!
I tried sorting products using various keys like created_at, updated_at, title, status and others, but the sorting only works for the id field.

Below is my package.json dependencies object for reference:

"dependencies": {
  "@aws-sdk/client-cognito-identity-provider": "^3.687.0",
  "@aws-sdk/client-s3": "^3.700.0",
  "@medusajs/admin-sdk": "2.1.1",
  "@medusajs/cli": "2.1.1",
  "@medusajs/framework": "2.1.1",
  "@medusajs/medusa": "2.1.1",
  "@mikro-orm/core": "5.9.7",
  "@mikro-orm/knex": "5.9.7",
  "@mikro-orm/migrations": "5.9.7",
  "@mikro-orm/postgresql": "5.9.7",
  "@smithy/node-http-handler": "^3.3.2",
  "@types/multer": "^1.4.12",
  "amazon-cognito-identity-js": "^6.3.12",
  "awilix": "^8.0.1",
  "jsonwebtoken": "^9.0.2",
  "moment": "^2.30.1",
  "multer": "^1.4.5-lts.1",
  "pg": "^8.13.0"
}

@SteelRazor47
Copy link

same here, but trying to order categories by rank. Seems like ordering support hasnt been added at all yet. I'm doing it frontend side for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants