fix(medusa): Free text search for PriceList Products (#1843)
**What** Fixes #1831 and #1336
This commit is contained in:
1 parent
cbdc5b7774
commit
7162972318
4 files changed
+41
-14
No files matched your search
@@ -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" }),
|
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", () => {
|
describe("delete prices from price list related to the specified product or variant", () => {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import {
|
|||||||
} from "typeorm"
|
} from "typeorm"
|
||||||
import { PriceList } from "../models/price-list"
|
import { PriceList } from "../models/price-list"
|
||||||
import { CustomFindOptions, ExtendedFindConfig } from "../types/common"
|
import { CustomFindOptions, ExtendedFindConfig } from "../types/common"
|
||||||
import { CustomerGroup } from "../models"
|
|
||||||
import { FilterablePriceListProps } from "../types/price-list"
|
import { FilterablePriceListProps } from "../types/price-list"
|
||||||
|
|
||||||
export type PriceListFindOptions = CustomFindOptions<
|
export type PriceListFindOptions = CustomFindOptions<
|
||||||
@@ -111,10 +110,10 @@ export class PriceListRepository extends Repository<PriceList> {
|
|||||||
.take(query.take)
|
.take(query.take)
|
||||||
|
|
||||||
if (groups) {
|
if (groups) {
|
||||||
qb.leftJoinAndSelect(
|
qb.leftJoinAndSelect("price_list.customer_groups", "group").andWhere(
|
||||||
"price_list.customer_groups",
|
"group.id IN (:...ids)",
|
||||||
"group"
|
{ ids: groups.value }
|
||||||
).andWhere("group.id IN (:...ids)", { ids: groups.value })
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query.relations?.length) {
|
if (query.relations?.length) {
|
||||||
|
|||||||
@@ -105,9 +105,7 @@ export class ProductRepository extends Repository<Product> {
|
|||||||
return [entities, count]
|
return [entities, count]
|
||||||
}
|
}
|
||||||
|
|
||||||
private getGroupedRelations(
|
private getGroupedRelations(relations: string[]): {
|
||||||
relations: string[]
|
|
||||||
): {
|
|
||||||
[toplevel: string]: string[]
|
[toplevel: string]: string[]
|
||||||
} {
|
} {
|
||||||
const groupedRelations: { [toplevel: string]: string[] } = {}
|
const groupedRelations: { [toplevel: string]: string[] } = {}
|
||||||
@@ -231,9 +229,8 @@ export class ProductRepository extends Repository<Product> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
||||||
const entitiesToReturn = this.mergeEntitiesWithRelations(
|
const entitiesToReturn =
|
||||||
entitiesAndRelations
|
this.mergeEntitiesWithRelations(entitiesAndRelations)
|
||||||
)
|
|
||||||
|
|
||||||
return [entitiesToReturn, count]
|
return [entitiesToReturn, count]
|
||||||
}
|
}
|
||||||
@@ -279,9 +276,8 @@ export class ProductRepository extends Repository<Product> {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
const entitiesAndRelations = entitiesIdsWithRelations.concat(entities)
|
||||||
const entitiesToReturn = this.mergeEntitiesWithRelations(
|
const entitiesToReturn =
|
||||||
entitiesAndRelations
|
this.mergeEntitiesWithRelations(entitiesAndRelations)
|
||||||
)
|
|
||||||
|
|
||||||
return entitiesToReturn
|
return entitiesToReturn
|
||||||
}
|
}
|
||||||
@@ -376,6 +372,10 @@ export class ProductRepository extends Repository<Product> {
|
|||||||
delete where.title
|
delete where.title
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("price_list_id" in where) {
|
||||||
|
delete where?.price_list_id
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...options,
|
...options,
|
||||||
where,
|
where,
|
||||||
|
|||||||
Reference in new issue
Block a user