medusajs / medusa

Building blocks for digital commerce
https://medusajs.com
MIT License
24.67k stars 2.43k forks source link

Extending Product Category results in productCategoryRepo.getFreeTextSearchResultsAndCount is not a function #8586

Closed aesher9o1 closed 1 month ago

aesher9o1 commented 1 month ago

Bug report

Describe the bug

Extending ProductCategory repository results in productCategoryRepo.getFreeTextSearchResultsAndCount

System information

Medusa version (including plugins): Node.js version: ^1.20.6 Database: PostgreSQL 16.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 13.2.1_git20240309) 13.2.1 20240309, 64-bit Operating system: macOS 14.5 Browser (if relevant): NA

Steps to reproduce the behavior

  1. Go to 'src.models/product-category.ts'
  2. Extend the repository
  3. Call GET /admin/product-categories

Expected behavior

A clear and concise description of what you expected to happen

Screenshots

TypeError: productCategoryRepo.getFreeTextSearchResultsAndCount is not a function
    at ProductCategoryService.<anonymous> (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:127:66)
    at step (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:59:23)
    at Object.next (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:40:53)
    at /Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:34:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:30:12)
    at ProductCategoryService.listAndCount (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/services/product-category.js:112:16)
    at /Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/api/routes/admin/product-categories/list-product-categories.js:185:61
    at step (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/api/routes/admin/product-categories/list-product-categories.js:57:23)
    at Object.next (/Users/aesher/Desktop/code/heyhomie/medusa/node_modules/@medusajs/medusa/dist/api/routes/admin/product-categories/list-product-categories.js:38:53)

Code snippets

@Tree("materialized-path")
export class ProductCategory extends MedusaProductCategory {
    @Index("product_category_store_id")
    @Column()
    store_id: string;

    @TreeParent()
    @JoinColumn({ name: "parent_category_id" })
    parent_category: ProductCategory | null;

    @TreeChildren({ cascade: true })
    category_children: ProductCategory[];
}

export const ProductCategoryRepository = dataSource
  .getTreeRepository(ProductCategory)
  .extend({
    ...Object.assign(MedusaProductCategoryRepository, {
      target: ProductCategory,
    }),
  });

export default ProductCategoryRepository;

Additional context

Add any other context about the problem here

srindom commented 1 month ago

We won't be able to allocate time to debug this. Will close for now - if anyone figures out why the core methods are not carried into the extended repository we'd be happy to look into this further.

voronovmaksim commented 3 weeks ago

I have the same isuue. @aesher9o1, have you managed to find a solution or any warkaround?

Upd: Answer is here https://github.com/medusajs/medusa/issues/4461#issuecomment-1620406462