@@ -23,3 +23,4 @@ export * from "./delete-product-tags"
|
||||
export * from "./generate-product-csv"
|
||||
export * from "./parse-product-csv"
|
||||
export * from "./group-products-for-batch"
|
||||
export * from "./wait-confirmation-product-import"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const waitConfirmationProductImportStepId =
|
||||
"wait-confirmation-product-import"
|
||||
export const waitConfirmationProductImportStep = createStep(
|
||||
{
|
||||
name: waitConfirmationProductImportStepId,
|
||||
async: true,
|
||||
// After an hour we want to timeout and cancel the import so we don't have orphaned workflows
|
||||
timeout: 60 * 60 * 1 * 1000,
|
||||
},
|
||||
async () => {}
|
||||
)
|
||||
@@ -5,7 +5,11 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { WorkflowTypes } from "@medusajs/types"
|
||||
import { sendNotificationsStep } from "../../notification"
|
||||
import { groupProductsForBatchStep, parseProductCsvStep } from "../steps"
|
||||
import {
|
||||
waitConfirmationProductImportStep,
|
||||
groupProductsForBatchStep,
|
||||
parseProductCsvStep,
|
||||
} from "../steps"
|
||||
import { batchProductsWorkflow } from "./batch-products"
|
||||
|
||||
export const importProductsWorkflowId = "import-products"
|
||||
@@ -13,11 +17,18 @@ export const importProductsWorkflow = createWorkflow(
|
||||
importProductsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<WorkflowTypes.ProductWorkflow.ImportProductsDTO>
|
||||
): WorkflowData<void> => {
|
||||
): WorkflowData<WorkflowTypes.ProductWorkflow.ImportProductsSummary> => {
|
||||
const products = parseProductCsvStep(input.fileContent)
|
||||
const batchRequest = groupProductsForBatchStep(products)
|
||||
|
||||
// TODO: Add async confirmation step here
|
||||
const summary = transform({ batchRequest }, (data) => {
|
||||
return {
|
||||
toCreate: data.batchRequest.create.length,
|
||||
toUpdate: data.batchRequest.update.length,
|
||||
}
|
||||
})
|
||||
|
||||
waitConfirmationProductImportStep()
|
||||
|
||||
batchProductsWorkflow.runAsStep({ input: batchRequest })
|
||||
|
||||
@@ -37,5 +48,6 @@ export const importProductsWorkflow = createWorkflow(
|
||||
})
|
||||
|
||||
sendNotificationsStep(notifications)
|
||||
return summary
|
||||
}
|
||||
)
|
||||
|
||||
@@ -32,11 +32,15 @@ export interface AdminProductVariantDeleteResponse
|
||||
extends DeleteResponse<"variant", AdminProduct> {}
|
||||
|
||||
export interface AdminExportProductResponse {
|
||||
workflow_id: string
|
||||
transaction_id: string
|
||||
}
|
||||
|
||||
export interface AdminImportProductResponse {
|
||||
workflow_id: string
|
||||
transaction_id: string
|
||||
summary: {
|
||||
toCreate: number
|
||||
toUpdate: number
|
||||
}
|
||||
}
|
||||
|
||||
export interface AdminBatchProductVariantResponse
|
||||
|
||||
@@ -2,3 +2,8 @@ export interface ImportProductsDTO {
|
||||
fileContent: string
|
||||
filename: string
|
||||
}
|
||||
|
||||
export interface ImportProductsSummary {
|
||||
toCreate: number
|
||||
toUpdate: number
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user