fix(medusa): Free text search for PriceList Products (#1843)
**What** Fixes #1831 and #1336
This commit is contained in:
committed by
GitHub
parent
cbdc5b7774
commit
7162972318
5
.changeset/new-flowers-remember.md
Normal file
5
.changeset/new-flowers-remember.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
Fixes free text search for PriceList Products
|
||||
@@ -1244,6 +1244,29 @@ describe("/admin/price-lists", () => {
|
||||
expect.objectContaining({ id: "test-prod-2" }),
|
||||
])
|
||||
})
|
||||
|
||||
it("lists products using free text search", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get(`/admin/price-lists/test-list/products?q=MedusaHeadphones`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn(err.response.data)
|
||||
})
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data.count).toEqual(1)
|
||||
expect(response.data.products).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-prod-1",
|
||||
title: "MedusaHeadphones",
|
||||
}),
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe("delete prices from price list related to the specified product or variant", () => {
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
} from "typeorm"
|
||||
import { PriceList } from "../models/price-list"
|
||||
import { CustomFindOptions, ExtendedFindConfig } from "../types/common"
|
||||
import { CustomerGroup } from "../models"
|
||||
import { FilterablePriceListProps } from "../types/price-list"
|
||||
|
||||
export type PriceListFindOptions = CustomFindOptions<
|
||||
@@ -111,10 +110,10 @@ export class PriceListRepository extends Repository<PriceList> {
|
||||
.take(query.take)
|
||||
|
||||
if (groups) {
|
||||
qb.leftJoinAndSelect(
|
||||
"price_list.customer_groups",
|
||||
"group"
|
||||
).andWhere("group.id IN (:...ids)", { ids: groups.value })
|
||||
qb.leftJoinAndSelect("price_list.customer_groups", "group").andWhere(
|
||||
"group.id IN (:...ids)",
|
||||
{ ids: groups.value }
|
||||
)
|
||||
}
|
||||
|
||||
if (query.relations?.length) {
|
||||
|
||||
@@ -105,9 +105,7 @@ export class ProductRepository extends Repository<Product> {
|
||||
return [entities, count]
|
||||
}
|
||||
|
||||
private getGroupedRelations(
|
||||
relations: string[]
|
||||
): {
|
||||
private getGroupedRelations(relations: string[]): {
|
||||
[toplevel: string]: string[]
|
||||
} {
|
||||
const groupedRelations: { [toplevel: string]: string[] } = {}
|
||||
@@ -231,9 +229,8 @@ export class ProductRepository extends Repository<Product> {
|
||||
)
|
||||
|
||||
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
||||
const entitiesToReturn = this.mergeEntitiesWithRelations(
|
||||
entitiesAndRelations
|
||||
)
|
||||
const entitiesToReturn =
|
||||
this.mergeEntitiesWithRelations(entitiesAndRelations)
|
||||
|
||||
return [entitiesToReturn, count]
|
||||
}
|
||||
@@ -279,9 +276,8 @@ export class ProductRepository extends Repository<Product> {
|
||||
)
|
||||
|
||||
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
||||
const entitiesToReturn = this.mergeEntitiesWithRelations(
|
||||
entitiesAndRelations
|
||||
)
|
||||
const entitiesToReturn =
|
||||
this.mergeEntitiesWithRelations(entitiesAndRelations)
|
||||
|
||||
return entitiesToReturn
|
||||
}
|
||||
@@ -376,6 +372,10 @@ export class ProductRepository extends Repository<Product> {
|
||||
delete where.title
|
||||
}
|
||||
|
||||
if ("price_list_id" in where) {
|
||||
delete where?.price_list_id
|
||||
}
|
||||
|
||||
return {
|
||||
...options,
|
||||
where,
|
||||
|
||||
Reference in New Issue
Block a user