fix: adds tax calculation to product pricing (#1354)

* fix: adds tax calculation to product pricing

* fix: dedupe

* fix: merge inconsistencies

* fix: merge inconsistencies
This commit is contained in:
Sebastian Rindom
2022-06-14 10:11:18 +02:00
committed by GitHub
parent 9a3ff32b42
commit 14366f536d
31 changed files with 792 additions and 434 deletions
@@ -3,7 +3,7 @@ import { AdminProductsListRes } from "../../api"
import { pickBy } from "lodash"
import { MedusaError } from "medusa-core-utils"
import { Product } from "../../models/product"
import { ProductService } from "../../services"
import { ProductService, PricingService } from "../../services"
import { getListConfig } from "../../utils/get-query-config"
import { FilterableProductProps } from "../../types/product"
@@ -24,10 +24,11 @@ const listAndCount = async (
body?: object,
context: ListContext = { limit: 50, offset: 0 }
): Promise<AdminProductsListRes> => {
const productService: ProductService = scope.resolve("productService")
const { limit, offset, allowedFields, defaultFields, defaultRelations } =
context
const productService: ProductService = scope.resolve("productService")
const pricingService: PricingService = scope.resolve("pricingService")
let includeFields: (keyof Product)[] | undefined
if (context.fields) {
includeFields = context.fields.split(",") as (keyof Product)[]
@@ -67,11 +68,20 @@ const listAndCount = async (
orderBy
)
const [products, count] = await productService.listAndCount(
const [rawProducts, count] = await productService.listAndCount(
pickBy(query, (val) => typeof val !== "undefined"),
listConfig
)
let products = rawProducts
const includesPricing = ["variants", "variants.prices"].every((relation) =>
listConfig?.relations?.includes(relation)
)
if (includesPricing) {
products = await pricingService.setProductPrices(rawProducts)
}
return {
products,
count,