From 01089d5bc81bc92311bb43b2d57d987fee378030 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:55:30 -0300 Subject: [PATCH] chore(core-flows): price list skip when no data (#11977) --- .changeset/wicked-tomatoes-dream.md | 5 +++++ .../src/price-list/steps/create-price-list-prices.ts | 6 +++++- .../src/price-list/steps/create-price-lists.ts | 6 +++++- .../src/price-list/steps/update-price-list-prices.ts | 6 +++++- .../src/price-list/steps/update-price-lists.ts | 6 +++++- .../src/price-list/steps/validate-price-lists.ts | 4 ++++ .../price-list/steps/validate-variant-price-links.ts | 11 ++++++----- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 .changeset/wicked-tomatoes-dream.md diff --git a/.changeset/wicked-tomatoes-dream.md b/.changeset/wicked-tomatoes-dream.md new file mode 100644 index 0000000000..d170a9a901 --- /dev/null +++ b/.changeset/wicked-tomatoes-dream.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +chore(core-flows): skip prices list ops when no data diff --git a/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts b/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts index ad4bb633ad..a199aa5d0b 100644 --- a/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/steps/create-price-list-prices.ts @@ -11,7 +11,7 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" export const createPriceListPricesStepId = "create-price-list-prices" /** * This step creates prices for a price list. - * + * * @example * const data = createPriceListPricesStep({ * data: [{ @@ -59,6 +59,10 @@ export const createPriceListPricesStep = createStep( } } + if (!priceListPricesToCreate.length) { + return new StepResponse([]) + } + const createdPrices = await pricingModule.addPriceListPrices( priceListPricesToCreate ) diff --git a/packages/core/core-flows/src/price-list/steps/create-price-lists.ts b/packages/core/core-flows/src/price-list/steps/create-price-lists.ts index 9a61dc0907..4210ddc16f 100644 --- a/packages/core/core-flows/src/price-list/steps/create-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/create-price-lists.ts @@ -9,7 +9,7 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk" export const createPriceListsStepId = "create-price-lists" /** * This step creates a price list. - * + * * @example * const data = createPriceListsStep({ * data: [{ @@ -37,6 +37,10 @@ export const createPriceListsStep = createStep( Modules.PRICING ) + if (!data.length) { + return new StepResponse([]) + } + const createData = data.map((priceListDTO) => { const { prices = [], ...rest } = priceListDTO const createPriceListData: CreatePriceListDTO = { ...rest } diff --git a/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts b/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts index 9e5608d333..b7d7594d23 100644 --- a/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts +++ b/packages/core/core-flows/src/price-list/steps/update-price-list-prices.ts @@ -15,7 +15,7 @@ import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk" export const updatePriceListPricesStepId = "update-price-list-prices" /** * This step updates a price list's prices. - * + * * @example * const data = updatePriceListPricesStep({ * data: [{ @@ -68,6 +68,10 @@ export const updatePriceListPricesStep = createStep( }) } + if (!priceListPricesToUpdate.length) { + return new StepResponse([]) + } + const existingPrices = priceIds.length ? await pricingModule.listPrices( { id: priceIds }, diff --git a/packages/core/core-flows/src/price-list/steps/update-price-lists.ts b/packages/core/core-flows/src/price-list/steps/update-price-lists.ts index 539fa6ca26..c37537d276 100644 --- a/packages/core/core-flows/src/price-list/steps/update-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/update-price-lists.ts @@ -19,7 +19,7 @@ export type UpdatePriceListsStepInput = UpdatePriceListWorkflowInputDTO[] export const updatePriceListsStepId = "update-price-lists" /** * This step updates one or more price lists. - * + * * @example * const data = updatePriceListsStep([ * { @@ -35,6 +35,10 @@ export const updatePriceListsStep = createStep( Modules.PRICING ) + if (!data.length) { + return new StepResponse(void 0) + } + const { dataBeforeUpdate, selects, relations } = await getDataBeforeUpdate( pricingModule, data diff --git a/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts b/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts index cd4e945ed1..fd9231a57e 100644 --- a/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts +++ b/packages/core/core-flows/src/price-list/steps/validate-price-lists.ts @@ -27,6 +27,10 @@ export const validatePriceListsStep = createStep( Modules.PRICING ) + if (!data.length) { + return new StepResponse(void 0) + } + const priceListIds = data.map((d) => d.id) const priceLists = await pricingModule.listPriceLists({ id: priceListIds }) diff --git a/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts b/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts index c296bcd7df..02a8de3591 100644 --- a/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts +++ b/packages/core/core-flows/src/price-list/steps/validate-variant-price-links.ts @@ -23,7 +23,7 @@ export const validateVariantPriceLinksStepId = "validate-variant-price-links" /** * This step validates that the specified variants have prices. * If not valid, the step throws an error. - * + * * @example * const data = validateVariantPriceLinksStep([ * { @@ -37,14 +37,15 @@ export const validateVariantPriceLinksStepId = "validate-variant-price-links" */ export const validateVariantPriceLinksStep = createStep( validateVariantPriceLinksStepId, - async ( - data: ValidateVariantPriceLinksStepInput, - { container } - ) => { + async (data: ValidateVariantPriceLinksStepInput, { container }) => { const remoteQuery = container.resolve( ContainerRegistrationKeys.REMOTE_QUERY ) + if (!data.length) { + return new StepResponse(void 0) + } + const variantIds: string[] = data .map((pl) => pl?.prices?.map((price) => price.variant_id) || []) .filter(Boolean)