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

View File

@@ -0,0 +1,5 @@
---
"@medusajs/core-flows": patch
---
chore(core-flows): skip prices list ops when no data

View File

@@ -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
)

View File

@@ -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 }

View File

@@ -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 },

View File

@@ -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

View File

@@ -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 })

View File

@@ -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)