fix(core-flows): fixes case where inventory attempts delete when input is empty (#9156)

what:

- when an empty array is passed to the workflow, it attempts to delete all inventory locations. This PR adds a conditional to prevent it from happening.

RESOLVES CC-477

Fixes https://github.com/medusajs/medusa/issues/9154
This commit is contained in:
Riqwan Thamir
2024-09-17 10:04:48 +02:00
committed by GitHub
parent 175ca30f4f
commit 987d007ba8
2 changed files with 48 additions and 5 deletions
@@ -1,6 +1,7 @@
import { InventoryLevelDTO, InventoryTypes } from "@medusajs/types"
import {
createWorkflow,
when,
WorkflowData,
WorkflowResponse,
} from "@medusajs/workflows-sdk"
@@ -22,12 +23,22 @@ export const bulkCreateDeleteLevelsWorkflow = createWorkflow(
(
input: WorkflowData<BulkCreateDeleteLevelsWorkflowInput>
): WorkflowResponse<InventoryLevelDTO[]> => {
deleteInventoryLevelsWorkflow.runAsStep({
input: {
$or: input.deletes,
},
when({ input }, ({ input }) => {
return !!input.deletes?.length
}).then(() => {
deleteInventoryLevelsWorkflow.runAsStep({
input: {
$or: input.deletes,
},
})
})
return new WorkflowResponse(createInventoryLevelsStep(input.creates))
const created = when({ input }, ({ input }) => {
return !!input.creates?.length
}).then(() => {
return createInventoryLevelsStep(input.creates)
})
return new WorkflowResponse(created || [])
}
)