medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.22k stars 2.66k forks source link

[CORE-901] Medusa js client missing order parameter #2657

Closed durdenx closed 1 year ago

durdenx commented 2 years ago

Bug report

Describe the bug

The order option doesn't exist on the medusa js client for some endpoints (products.list in this case) :

const medusaClient = new Medusa({
  baseUrl: config.medusa.baseUrl,
  apiKey: config.medusa.secretKey,
  maxRetries: 3,
});

medusaClient.admin.products.list({
    offset: 0,
    limit: 20,
    order: "-title" // this is not working
  });

Could you regenerate the client or something?

System information

Medusa version (including plugins):

Node.js version: 18.12.1 Database: postgres 13.8 Operating system: MacOS 12.6.1 Browser (if relevant): 107.0.5304.110

Steps to reproduce the behavior

Use the medusaClient with the order parameter.

Expected behavior

The order parameter is available in all list endpoints (especially the admin.products.list one) of the medusajs client and the client returns a sorted result with the provided parameter.

Bonus!

I don't know if this is intended, but the client wants you to provide all the list type fields when updating:

await medusaClient.admin.products.update(productId,
{
  collection_id: collectionId,

  // Needed to fix type issues
  // If we provide an empty array, the field value is overwritten.
  images: undefined as any,
  sales_channels: undefined as any,
}

Context

CORE-901

olivermrbl commented 2 years ago

Thanks for reporting this. We will attend to it in the near future 💪

edihasaj commented 1 year ago

any news on this?

olivermrbl commented 1 year ago

@edihasaj Solved in #2815. Did you test it yet?

bkvaiude commented 1 year ago

@olivermrbl I'm looking for the solution where I can sort by multiple columns

For example:

Select * from products order by discounts, created_at desc

in query params

store/products?size=XL&order[]=discounts&order[]=-created_at

It will helpful if guide how to solve this problem

I also looked into extending the StoreGetProductsPaginationParams