fix(medusa): Fix q param on /admin/price-lists/:id/products (#2813)

This commit is contained in:
Kasper Fabricius Kristensen
2022-12-18 20:11:38 +01:00
committed by GitHub
parent 5e4decbc1c
commit 9e05fef4b9
3 changed files with 56 additions and 4 deletions

View File

@@ -353,6 +353,18 @@ export class ProductRepository extends Repository<Product> {
options: FindWithoutRelationsOptions = { where: {} },
relations: string[] = []
): Promise<[Product[], number]> {
const tags = options.where.tags
delete options.where.tags
const price_lists = options.where.price_list_id
delete options.where.price_list_id
const sales_channels = options.where.sales_channel_id
delete options.where.sales_channel_id
const discount_condition_id = options.where.discount_condition_id
delete options.where.discount_condition_id
const cleanedOptions = this._cleanOptions(options)
let qb = this.createQueryBuilder("product")
@@ -372,13 +384,35 @@ export class ProductRepository extends Repository<Product> {
.skip(cleanedOptions.skip)
.take(cleanedOptions.take)
const discountConditionId = options.where.discount_condition_id
if (discountConditionId) {
if (discount_condition_id) {
qb.innerJoin(
"discount_condition_product",
"dc_product",
`dc_product.product_id = product.id AND dc_product.condition_id = :dcId`,
{ dcId: discountConditionId }
{ dcId: discount_condition_id }
)
}
if (tags) {
qb.leftJoin("product.tags", "tags").andWhere(`tags.id IN (:...tag_ids)`, {
tag_ids: tags.value,
})
}
if (price_lists) {
qb.leftJoin("product.variants", "variants")
.leftJoin("variants.prices", "ma")
.andWhere("ma.price_list_id IN (:...price_list_ids)", {
price_list_ids: price_lists.value,
})
}
if (sales_channels) {
qb.innerJoin(
"product.sales_channels",
"sales_channels",
"sales_channels.id IN (:...sales_channels_ids)",
{ sales_channels_ids: sales_channels.value }
)
}