feat(medusa,core-flows,types): adds batch operations to price list prices (#7077)
what: - adds batch operations to price list prices RESOLVES CORE-1969 RESOLVES CORE-1970
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { CreatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createPriceListPricesWorkflow } from "../workflows/create-price-list-prices"
|
||||
|
||||
export const createPriceListPricesWorkflowStepId =
|
||||
"create-price-list-prices-workflow-step"
|
||||
export const createPriceListPricesWorkflowStep = createStep(
|
||||
createPriceListPricesWorkflowStepId,
|
||||
async (data: CreatePriceListPricesWorkflowDTO[], { container }) => {
|
||||
const { transaction, result: created } =
|
||||
await createPriceListPricesWorkflow(container).run({ input: { data } })
|
||||
|
||||
return new StepResponse(created, transaction)
|
||||
},
|
||||
|
||||
async (transaction, { container }) => {
|
||||
if (!transaction) {
|
||||
return
|
||||
}
|
||||
|
||||
await createPriceListPricesWorkflow(container).cancel({ transaction })
|
||||
}
|
||||
)
|
||||
@@ -41,7 +41,7 @@ export const createPriceListPricesStep = createStep(
|
||||
)
|
||||
|
||||
return new StepResponse(
|
||||
null,
|
||||
createdPrices,
|
||||
createdPrices.map((p) => p.id)
|
||||
)
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ export const getExistingPriceListsPriceIdsStep = createStep(
|
||||
const existingPrices = priceListIds.length
|
||||
? await pricingModule.listPrices(
|
||||
{ price_list_id: priceListIds },
|
||||
{ relations: ["price_list"] }
|
||||
{ relations: ["price_list"], take: null }
|
||||
)
|
||||
: []
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
export * from "./create-price-list-prices"
|
||||
export * from "./create-price-list-prices-workflow"
|
||||
export * from "./create-price-lists"
|
||||
export * from "./delete-price-lists"
|
||||
export * from "./get-existing-price-lists-price-ids"
|
||||
export * from "./remove-price-list-prices"
|
||||
export * from "./remove-price-list-prices-workflow"
|
||||
export * from "./update-price-list-prices"
|
||||
export * from "./update-price-list-prices-workflow"
|
||||
export * from "./update-price-lists"
|
||||
export * from "./validate-price-lists"
|
||||
export * from "./validate-variant-price-links"
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { removePriceListPricesWorkflow } from "../workflows/remove-price-list-prices"
|
||||
|
||||
export const removePriceListPricesWorkflowStepId =
|
||||
"remove-price-list-prices-workflow"
|
||||
export const removePriceListPricesWorkflowStep = createStep(
|
||||
removePriceListPricesWorkflowStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
const { transaction, result: updated } =
|
||||
await removePriceListPricesWorkflow(container).run({ input: { ids } })
|
||||
|
||||
return new StepResponse(updated, transaction)
|
||||
},
|
||||
|
||||
async (transaction, { container }) => {
|
||||
if (!transaction) {
|
||||
return
|
||||
}
|
||||
|
||||
await removePriceListPricesWorkflow(container).cancel({ transaction })
|
||||
}
|
||||
)
|
||||
@@ -7,7 +7,7 @@ export const removePriceListPricesStep = createStep(
|
||||
removePriceListPricesStepId,
|
||||
async (ids: string[], { container }) => {
|
||||
if (!ids.length) {
|
||||
return new StepResponse(null, [])
|
||||
return new StepResponse([], [])
|
||||
}
|
||||
|
||||
const pricingModule = container.resolve<IPricingModuleService>(
|
||||
@@ -19,12 +19,11 @@ export const removePriceListPricesStep = createStep(
|
||||
{ relations: ["price_list"] }
|
||||
)
|
||||
|
||||
await pricingModule.softDeletePrices(prices.map((price) => price.id))
|
||||
const priceIds = prices.map((price) => price.id)
|
||||
|
||||
return new StepResponse(
|
||||
null,
|
||||
prices.map((price) => price.id)
|
||||
)
|
||||
await pricingModule.softDeletePrices(priceIds)
|
||||
|
||||
return new StepResponse(priceIds, priceIds)
|
||||
},
|
||||
async (ids, { container }) => {
|
||||
if (!ids?.length) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { UpdatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { updatePriceListPricesWorkflow } from "../workflows/update-price-list-prices"
|
||||
|
||||
export const updatePriceListPricesWorkflowStepId =
|
||||
"update-price-list-prices-workflow"
|
||||
export const updatePriceListPricesWorkflowStep = createStep(
|
||||
updatePriceListPricesWorkflowStepId,
|
||||
async (data: UpdatePriceListPricesWorkflowDTO[], { container }) => {
|
||||
const { transaction, result: updated } =
|
||||
await updatePriceListPricesWorkflow(container).run({ input: { data } })
|
||||
|
||||
return new StepResponse(updated, transaction)
|
||||
},
|
||||
|
||||
async (transaction, { container }) => {
|
||||
if (!transaction) {
|
||||
return
|
||||
}
|
||||
|
||||
await updatePriceListPricesWorkflow(container).cancel({ transaction })
|
||||
}
|
||||
)
|
||||
@@ -65,9 +65,11 @@ export const updatePriceListPricesStep = createStep(
|
||||
})
|
||||
}
|
||||
|
||||
await pricingModule.updatePriceListPrices(priceListPricesToUpdate)
|
||||
const updatedPrices = await pricingModule.updatePriceListPrices(
|
||||
priceListPricesToUpdate
|
||||
)
|
||||
|
||||
return new StepResponse(null, dataBeforePriceUpdate)
|
||||
return new StepResponse(updatedPrices, dataBeforePriceUpdate)
|
||||
},
|
||||
async (dataBeforePriceUpdate, { container }) => {
|
||||
if (!dataBeforePriceUpdate?.length) {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const validateVariantPriceLinksStep = createStep(
|
||||
validateVariantPriceLinksStepId,
|
||||
async (
|
||||
data: {
|
||||
prices: {
|
||||
prices?: {
|
||||
variant_id: string
|
||||
}[]
|
||||
}[],
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
BatchPriceListPricesWorkflowDTO,
|
||||
BatchPriceListPricesWorkflowResult,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createPriceListPricesWorkflowStep } from "../steps/create-price-list-prices-workflow"
|
||||
import { removePriceListPricesWorkflowStep } from "../steps/remove-price-list-prices-workflow"
|
||||
import { updatePriceListPricesWorkflowStep } from "../steps/update-price-list-prices-workflow"
|
||||
|
||||
export const batchPriceListPricesWorkflowId = "batch-price-list-prices"
|
||||
export const batchPriceListPricesWorkflow = createWorkflow(
|
||||
batchPriceListPricesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<{
|
||||
data: BatchPriceListPricesWorkflowDTO
|
||||
}>
|
||||
): WorkflowData<BatchPriceListPricesWorkflowResult> => {
|
||||
const createInput = transform({ input: input.data }, (data) => [
|
||||
{ id: data.input.id, prices: data.input.create },
|
||||
])
|
||||
|
||||
const updateInput = transform({ input: input.data }, (data) => [
|
||||
{ id: data.input.id, prices: data.input.update },
|
||||
])
|
||||
|
||||
const [created, updated, deleted] = parallelize(
|
||||
createPriceListPricesWorkflowStep(createInput),
|
||||
updatePriceListPricesWorkflowStep(updateInput),
|
||||
removePriceListPricesWorkflowStep(input.data.delete)
|
||||
)
|
||||
|
||||
return transform({ created, updated, deleted }, (data) => data)
|
||||
}
|
||||
)
|
||||
@@ -1,14 +1,13 @@
|
||||
import { CreatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { PricingTypes } from "@medusajs/types/src"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
createPriceListPricesStep,
|
||||
validatePriceListsStep,
|
||||
validateVariantPriceLinksStep,
|
||||
} from "../steps"
|
||||
import { createPriceListPricesStep } from "../steps/create-price-list-prices"
|
||||
import { validatePriceListsStep } from "../steps/validate-price-lists"
|
||||
import { validateVariantPriceLinksStep } from "../steps/validate-variant-price-links"
|
||||
|
||||
export const createPriceListPricesWorkflowId = "create-price-list-prices"
|
||||
export const createPriceListPricesWorkflow = createWorkflow(
|
||||
@@ -17,13 +16,13 @@ export const createPriceListPricesWorkflow = createWorkflow(
|
||||
input: WorkflowData<{
|
||||
data: CreatePriceListPricesWorkflowDTO[]
|
||||
}>
|
||||
): WorkflowData<void> => {
|
||||
): WorkflowData<PricingTypes.PriceDTO[]> => {
|
||||
const [_, variantPriceMap] = parallelize(
|
||||
validatePriceListsStep(input.data),
|
||||
validateVariantPriceLinksStep(input.data)
|
||||
)
|
||||
|
||||
createPriceListPricesStep({
|
||||
return createPriceListPricesStep({
|
||||
data: input.data,
|
||||
variant_price_map: variantPriceMap,
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export * from "./batch-price-list-prices"
|
||||
export * from "./create-price-list-prices"
|
||||
export * from "./create-price-lists"
|
||||
export * from "./delete-price-lists"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { removePriceListPricesStep } from "../steps"
|
||||
import { removePriceListPricesStep } from "../steps/remove-price-list-prices"
|
||||
|
||||
export const removePriceListPricesWorkflowId = "remove-price-list-prices"
|
||||
export const removePriceListPricesWorkflow = createWorkflow(
|
||||
removePriceListPricesWorkflowId,
|
||||
(input: WorkflowData<{ ids: string[] }>): WorkflowData<void> => {
|
||||
removePriceListPricesStep(input.ids)
|
||||
(input: WorkflowData<{ ids: string[] }>): WorkflowData<string[]> => {
|
||||
return removePriceListPricesStep(input.ids)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { UpdatePriceListPricesWorkflowDTO } from "@medusajs/types"
|
||||
import { PricingTypes } from "@medusajs/types/src"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
updatePriceListPricesStep,
|
||||
validatePriceListsStep,
|
||||
validateVariantPriceLinksStep,
|
||||
} from "../steps"
|
||||
import { updatePriceListPricesStep } from "../steps/update-price-list-prices"
|
||||
import { validatePriceListsStep } from "../steps/validate-price-lists"
|
||||
import { validateVariantPriceLinksStep } from "../steps/validate-variant-price-links"
|
||||
|
||||
export const updatePriceListPricesWorkflowId = "update-price-list-prices"
|
||||
export const updatePriceListPricesWorkflow = createWorkflow(
|
||||
@@ -17,13 +16,13 @@ export const updatePriceListPricesWorkflow = createWorkflow(
|
||||
input: WorkflowData<{
|
||||
data: UpdatePriceListPricesWorkflowDTO[]
|
||||
}>
|
||||
): WorkflowData<void> => {
|
||||
): WorkflowData<PricingTypes.PriceDTO[]> => {
|
||||
const [_, variantPriceMap] = parallelize(
|
||||
validatePriceListsStep(input.data),
|
||||
validateVariantPriceLinksStep(input.data)
|
||||
)
|
||||
|
||||
updatePriceListPricesStep({
|
||||
return updatePriceListPricesStep({
|
||||
data: input.data,
|
||||
variant_price_map: variantPriceMap,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user