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
@@ -11,7 +11,7 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
export const createPriceListPricesStepId = "create-price-list-prices" export const createPriceListPricesStepId = "create-price-list-prices"
/** /**
* This step creates prices for a price list. * This step creates prices for a price list.
* *
* @example * @example
* const data = createPriceListPricesStep({ * const data = createPriceListPricesStep({
* data: [{ * 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
) )
@@ -9,7 +9,7 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
export const createPriceListsStepId = "create-price-lists" export const createPriceListsStepId = "create-price-lists"
/** /**
* This step creates a price list. * This step creates a price list.
* *
* @example * @example
* const data = createPriceListsStep({ * const data = createPriceListsStep({
* data: [{ * data: [{
@@ -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 }
@@ -15,7 +15,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
export const updatePriceListPricesStepId = "update-price-list-prices" export const updatePriceListPricesStepId = "update-price-list-prices"
/** /**
* This step updates a price list's prices. * This step updates a price list's prices.
* *
* @example * @example
* const data = updatePriceListPricesStep({ * const data = updatePriceListPricesStep({
* data: [{ * data: [{
@@ -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 },
@@ -19,7 +19,7 @@ export type UpdatePriceListsStepInput = UpdatePriceListWorkflowInputDTO[]
export const updatePriceListsStepId = "update-price-lists" export const updatePriceListsStepId = "update-price-lists"
/** /**
* This step updates one or more price lists. * This step updates one or more price lists.
* *
* @example * @example
* const data = updatePriceListsStep([ * const data = updatePriceListsStep([
* { * {
@@ -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 })
@@ -23,7 +23,7 @@ export const validateVariantPriceLinksStepId = "validate-variant-price-links"
/** /**
* This step validates that the specified variants have prices. * This step validates that the specified variants have prices.
* If not valid, the step throws an error. * If not valid, the step throws an error.
* *
* @example * @example
* const data = validateVariantPriceLinksStep([ * const data = validateVariantPriceLinksStep([
* { * {
@@ -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)