chore(core-flows): price list skip when no data (#11977)

This commit is contained in:
Carlos R. L. Rodrigues
2025-03-25 10:55:30 -03:00
committed by GitHub
parent 83e063229b
commit 01089d5bc8
7 changed files with 35 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/core-flows": patch
---
chore(core-flows): skip prices list ops when no data
@@ -59,6 +59,10 @@ export const createPriceListPricesStep = createStep(
} }
} }
if (!priceListPricesToCreate.length) {
return new StepResponse([])
}
const createdPrices = await pricingModule.addPriceListPrices( const createdPrices = await pricingModule.addPriceListPrices(
priceListPricesToCreate priceListPricesToCreate
) )
@@ -37,6 +37,10 @@ export const createPriceListsStep = createStep(
Modules.PRICING Modules.PRICING
) )
if (!data.length) {
return new StepResponse([])
}
const createData = data.map((priceListDTO) => { const createData = data.map((priceListDTO) => {
const { prices = [], ...rest } = priceListDTO const { prices = [], ...rest } = priceListDTO
const createPriceListData: CreatePriceListDTO = { ...rest } const createPriceListData: CreatePriceListDTO = { ...rest }
@@ -68,6 +68,10 @@ export const updatePriceListPricesStep = createStep(
}) })
} }
if (!priceListPricesToUpdate.length) {
return new StepResponse([])
}
const existingPrices = priceIds.length const existingPrices = priceIds.length
? await pricingModule.listPrices( ? await pricingModule.listPrices(
{ id: priceIds }, { id: priceIds },
@@ -35,6 +35,10 @@ export const updatePriceListsStep = createStep(
Modules.PRICING Modules.PRICING
) )
if (!data.length) {
return new StepResponse(void 0)
}
const { dataBeforeUpdate, selects, relations } = await getDataBeforeUpdate( const { dataBeforeUpdate, selects, relations } = await getDataBeforeUpdate(
pricingModule, pricingModule,
data data
@@ -27,6 +27,10 @@ export const validatePriceListsStep = createStep(
Modules.PRICING Modules.PRICING
) )
if (!data.length) {
return new StepResponse(void 0)
}
const priceListIds = data.map((d) => d.id) const priceListIds = data.map((d) => d.id)
const priceLists = await pricingModule.listPriceLists({ id: priceListIds }) const priceLists = await pricingModule.listPriceLists({ id: priceListIds })
@@ -37,14 +37,15 @@ export const validateVariantPriceLinksStepId = "validate-variant-price-links"
*/ */
export const validateVariantPriceLinksStep = createStep( export const validateVariantPriceLinksStep = createStep(
validateVariantPriceLinksStepId, validateVariantPriceLinksStepId,
async ( async (data: ValidateVariantPriceLinksStepInput, { container }) => {
data: ValidateVariantPriceLinksStepInput,
{ container }
) => {
const remoteQuery = container.resolve( const remoteQuery = container.resolve(
ContainerRegistrationKeys.REMOTE_QUERY ContainerRegistrationKeys.REMOTE_QUERY
) )
if (!data.length) {
return new StepResponse(void 0)
}
const variantIds: string[] = data const variantIds: string[] = data
.map((pl) => pl?.prices?.map((price) => price.variant_id) || []) .map((pl) => pl?.prices?.map((price) => price.variant_id) || [])
.filter(Boolean) .filter(Boolean)