chore(core-flows): [13] export types and steps, add basic TSDocs (#8523)
This commit is contained in:
@@ -5,6 +5,9 @@ import { batchLinkProductsToCollectionStep } from "../steps/batch-link-products-
|
||||
export const batchLinkProductsToCollectionWorkflowId =
|
||||
"batch-link-products-to-collection"
|
||||
|
||||
/**
|
||||
* This workflow creates links between product and collection records.
|
||||
*/
|
||||
export const batchLinkProductsToCollectionWorkflow = createWorkflow(
|
||||
batchLinkProductsToCollectionWorkflowId,
|
||||
(input: WorkflowData<LinkWorkflowInput>): WorkflowData<void> => {
|
||||
|
||||
@@ -17,6 +17,9 @@ import { updateProductVariantsWorkflow } from "./update-product-variants"
|
||||
import { deleteProductVariantsWorkflow } from "./delete-product-variants"
|
||||
|
||||
export const batchProductVariantsWorkflowId = "batch-product-variants"
|
||||
/**
|
||||
* This workflow creates, updates, and deletes product variants.
|
||||
*/
|
||||
export const batchProductVariantsWorkflow = createWorkflow(
|
||||
batchProductVariantsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -4,6 +4,9 @@ import { batchLinkProductsToCategoryStep } from "../steps/batch-link-products-in
|
||||
|
||||
export const batchLinkProductsToCategoryWorkflowId =
|
||||
"batch-link-products-to-category"
|
||||
/**
|
||||
* This workflow creates links between product and category records.
|
||||
*/
|
||||
export const batchLinkProductsToCategoryWorkflow = createWorkflow(
|
||||
batchLinkProductsToCategoryWorkflowId,
|
||||
(
|
||||
|
||||
@@ -17,6 +17,9 @@ import { deleteProductsWorkflow } from "./delete-products"
|
||||
import { updateProductsWorkflow } from "./update-products"
|
||||
|
||||
export const batchProductsWorkflowId = "batch-products"
|
||||
/**
|
||||
* This workflow creates, updates, or deletes products.
|
||||
*/
|
||||
export const batchProductsWorkflow = createWorkflow(
|
||||
batchProductsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -7,14 +7,17 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createCollectionsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type CreateCollectionsWorkflowInput = {
|
||||
collections: ProductTypes.CreateProductCollectionDTO[]
|
||||
} & AdditionalData
|
||||
|
||||
export const createCollectionsWorkflowId = "create-collections"
|
||||
/**
|
||||
* This workflow creates one or more collections.
|
||||
*/
|
||||
export const createCollectionsWorkflow = createWorkflow(
|
||||
createCollectionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateCollectionsWorkflowInput>) => {
|
||||
const collections = createCollectionsStep(input.collections)
|
||||
const collectionsCreated = createHook("collectionsCreated", {
|
||||
collections,
|
||||
|
||||
@@ -7,15 +7,17 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createProductOptionsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type CreateProductOptionsWorkflowInput = {
|
||||
product_options: ProductTypes.CreateProductOptionDTO[]
|
||||
} & AdditionalData
|
||||
|
||||
export const createProductOptionsWorkflowId = "create-product-options"
|
||||
|
||||
/**
|
||||
* This workflow creates one or more product options.
|
||||
*/
|
||||
export const createProductOptionsWorkflow = createWorkflow(
|
||||
createProductOptionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateProductOptionsWorkflowInput>) => {
|
||||
const productOptions = createProductOptionsStep(input.product_options)
|
||||
const productOptionsCreated = createHook("productOptionsCreated", {
|
||||
product_options: productOptions,
|
||||
|
||||
@@ -7,15 +7,17 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createProductTagsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type CreateProductTagsWorkflowInput = {
|
||||
product_tags: ProductTypes.CreateProductTagDTO[]
|
||||
} & AdditionalData
|
||||
|
||||
export const createProductTagsWorkflowId = "create-product-tags"
|
||||
|
||||
/**
|
||||
* This workflow creates one or more product tags.
|
||||
*/
|
||||
export const createProductTagsWorkflow = createWorkflow(
|
||||
createProductTagsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateProductTagsWorkflowInput>) => {
|
||||
const productTags = createProductTagsStep(input.product_tags)
|
||||
const productTagsCreated = createHook("productTagsCreated", {
|
||||
product_tags: productTags,
|
||||
|
||||
@@ -7,15 +7,17 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createProductTypesStep } from "../steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type CreateProductTypesWorkflowInput = {
|
||||
product_types: ProductTypes.CreateProductTypeDTO[]
|
||||
} & AdditionalData
|
||||
|
||||
export const createProductTypesWorkflowId = "create-product-types"
|
||||
|
||||
/**
|
||||
* This workflow creates one or more product types.
|
||||
*/
|
||||
export const createProductTypesWorkflow = createWorkflow(
|
||||
createProductTypesWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateProductTypesWorkflowInput>) => {
|
||||
const productTypes = createProductTypesStep(input.product_types)
|
||||
const productTypesCreated = createHook("productTypesCreated", {
|
||||
product_types: productTypes,
|
||||
|
||||
@@ -20,8 +20,11 @@ import { createProductVariantsStep } from "../steps/create-product-variants"
|
||||
import { createVariantPricingLinkStep } from "../steps/create-variant-pricing-link"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
// TODO: Create separate typings for the workflow input
|
||||
type WorkflowInput = {
|
||||
/**
|
||||
* @privateRemarks
|
||||
* TODO: Create separate typings for the workflow input
|
||||
*/
|
||||
export type CreateProductVariantsWorkflowInput = {
|
||||
product_variants: (ProductTypes.CreateProductVariantDTO & {
|
||||
prices?: PricingTypes.CreateMoneyAmountDTO[]
|
||||
} & {
|
||||
@@ -49,7 +52,7 @@ const buildLink = (
|
||||
const buildLinksToCreate = (data: {
|
||||
createdVariants: ProductTypes.ProductVariantDTO[]
|
||||
inventoryIndexMap: Record<number, InventoryTypes.InventoryItemDTO>
|
||||
input: WorkflowInput
|
||||
input: CreateProductVariantsWorkflowInput
|
||||
}) => {
|
||||
let index = 0
|
||||
const linksToCreate: LinkDefinition[] = []
|
||||
@@ -88,7 +91,7 @@ const buildLinksToCreate = (data: {
|
||||
|
||||
const buildVariantItemCreateMap = (data: {
|
||||
createdVariants: ProductTypes.ProductVariantDTO[]
|
||||
input: WorkflowInput
|
||||
input: CreateProductVariantsWorkflowInput
|
||||
}) => {
|
||||
let index = 0
|
||||
const map: Record<number, InventoryTypes.CreateInventoryItemInput> = {}
|
||||
@@ -124,10 +127,12 @@ const buildVariantItemCreateMap = (data: {
|
||||
}
|
||||
|
||||
export const createProductVariantsWorkflowId = "create-product-variants"
|
||||
|
||||
/**
|
||||
* This workflow creates one or more product variants.
|
||||
*/
|
||||
export const createProductVariantsWorkflow = createWorkflow(
|
||||
createProductVariantsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateProductVariantsWorkflowInput>) => {
|
||||
// Passing prices to the product module will fail, we want to keep them for after the variant is created.
|
||||
const variantsWithoutPrices = transform({ input }, (data) =>
|
||||
data.input.product_variants.map((v) => ({
|
||||
|
||||
@@ -16,15 +16,17 @@ import { associateProductsWithSalesChannelsStep } from "../../sales-channel"
|
||||
import { createProductsStep } from "../steps/create-products"
|
||||
import { createProductVariantsWorkflow } from "./create-product-variants"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type CreateProductsWorkflowInput = {
|
||||
products: CreateProductWorkflowInputDTO[]
|
||||
} & AdditionalData
|
||||
|
||||
export const createProductsWorkflowId = "create-products"
|
||||
|
||||
/**
|
||||
* This workflow creates one or more products.
|
||||
*/
|
||||
export const createProductsWorkflow = createWorkflow(
|
||||
createProductsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<CreateProductsWorkflowInput>) => {
|
||||
// Passing prices to the product module will fail, we want to keep them for after the product is created.
|
||||
const productWithoutExternalRelations = transform({ input }, (data) =>
|
||||
data.input.products.map((p) => ({
|
||||
|
||||
@@ -6,13 +6,15 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { deleteCollectionsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteCollectionsWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteCollectionsWorkflowId = "delete-collections"
|
||||
|
||||
/**
|
||||
* This workflow deletes one or more collection.
|
||||
*/
|
||||
export const deleteCollectionsWorkflow = createWorkflow(
|
||||
deleteCollectionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteCollectionsWorkflowInput>) => {
|
||||
const deletedCollections = deleteCollectionsStep(input.ids)
|
||||
const collectionsDeleted = createHook("collectionsDeleted", {
|
||||
ids: input.ids,
|
||||
|
||||
@@ -6,12 +6,15 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { deleteProductOptionsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteProductOptionsWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteProductOptionsWorkflowId = "delete-product-options"
|
||||
/**
|
||||
* This workflow deletes one or more product options.
|
||||
*/
|
||||
export const deleteProductOptionsWorkflow = createWorkflow(
|
||||
deleteProductOptionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteProductOptionsWorkflowInput>) => {
|
||||
const deletedProductOptions = deleteProductOptionsStep(input.ids)
|
||||
const productOptionsDeleted = createHook("productOptionsDeleted", {
|
||||
ids: input.ids,
|
||||
|
||||
@@ -6,12 +6,15 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { deleteProductTagsStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteProductTagsWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteProductTagsWorkflowId = "delete-product-tags"
|
||||
/**
|
||||
* This workflow deletes one or more product tags.
|
||||
*/
|
||||
export const deleteProductTagsWorkflow = createWorkflow(
|
||||
deleteProductTagsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteProductTagsWorkflowInput>) => {
|
||||
const deletedProductTags = deleteProductTagsStep(input.ids)
|
||||
const productTagsDeleted = createHook("productTagsDeleted", {
|
||||
ids: input.ids,
|
||||
|
||||
@@ -6,12 +6,15 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { deleteProductTypesStep } from "../steps"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteProductTypesWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteProductTypesWorkflowId = "delete-product-types"
|
||||
/**
|
||||
* This workflow deletes one or more product types.
|
||||
*/
|
||||
export const deleteProductTypesWorkflow = createWorkflow(
|
||||
deleteProductTypesWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteProductTypesWorkflowInput>) => {
|
||||
const deletedProductTypes = deleteProductTypesStep(input.ids)
|
||||
const productTypesDeleted = createHook("productTypesDeleted", {
|
||||
ids: input.ids,
|
||||
|
||||
@@ -8,12 +8,15 @@ import { deleteProductVariantsStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteProductVariantsWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteProductVariantsWorkflowId = "delete-product-variants"
|
||||
/**
|
||||
* This workflow deletes one or more product variants.
|
||||
*/
|
||||
export const deleteProductVariantsWorkflow = createWorkflow(
|
||||
deleteProductVariantsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteProductVariantsWorkflowInput>) => {
|
||||
removeRemoteLinkStep({
|
||||
[Modules.PRODUCT]: { variant_id: input.ids },
|
||||
}).config({ name: "remove-variant-link-step" })
|
||||
|
||||
@@ -11,12 +11,15 @@ import { deleteProductsStep } from "../steps/delete-products"
|
||||
import { getProductsStep } from "../steps/get-products"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
export type DeleteProductsWorkflowInput = { ids: string[] }
|
||||
|
||||
export const deleteProductsWorkflowId = "delete-products"
|
||||
/**
|
||||
* This workflow deletes one or more products.
|
||||
*/
|
||||
export const deleteProductsWorkflow = createWorkflow(
|
||||
deleteProductsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<DeleteProductsWorkflowInput>) => {
|
||||
const productsToDelete = getProductsStep({ ids: input.ids })
|
||||
const variantsToBeDeleted = transform({ productsToDelete }, (data) => {
|
||||
return data.productsToDelete
|
||||
|
||||
@@ -9,6 +9,9 @@ import { useRemoteQueryStep } from "../../common"
|
||||
import { notifyOnFailureStep, sendNotificationsStep } from "../../notification"
|
||||
|
||||
export const exportProductsWorkflowId = "export-products"
|
||||
/**
|
||||
* This workflow exports products matching the specified filters.
|
||||
*/
|
||||
export const exportProductsWorkflow = createWorkflow(
|
||||
exportProductsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -14,6 +14,9 @@ import {
|
||||
import { batchProductsWorkflow } from "./batch-products"
|
||||
|
||||
export const importProductsWorkflowId = "import-products"
|
||||
/**
|
||||
* This workflow imports products from a CSV file.
|
||||
*/
|
||||
export const importProductsWorkflow = createWorkflow(
|
||||
importProductsWorkflowId,
|
||||
(
|
||||
|
||||
@@ -7,17 +7,18 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { updateCollectionsStep } from "../steps"
|
||||
|
||||
type UpdateCollectionsStepInput = {
|
||||
export type UpdateCollectionsWorkflowInput = {
|
||||
selector: ProductTypes.FilterableProductCollectionProps
|
||||
update: ProductTypes.UpdateProductCollectionDTO
|
||||
} & AdditionalData
|
||||
|
||||
type WorkflowInput = UpdateCollectionsStepInput
|
||||
|
||||
export const updateCollectionsWorkflowId = "update-collections"
|
||||
/**
|
||||
* This workflow updates collections matching the specified filters.
|
||||
*/
|
||||
export const updateCollectionsWorkflow = createWorkflow(
|
||||
updateCollectionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateCollectionsWorkflowInput>) => {
|
||||
const updatedCollections = updateCollectionsStep(input)
|
||||
const collectionsUpdated = createHook("collectionsUpdated", {
|
||||
additional_data: input.additional_data,
|
||||
|
||||
@@ -7,17 +7,18 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { updateProductOptionsStep } from "../steps"
|
||||
|
||||
type UpdateProductOptionsStepInput = {
|
||||
export type UpdateProductOptionsWorkflowInput = {
|
||||
selector: ProductTypes.FilterableProductOptionProps
|
||||
update: ProductTypes.UpdateProductOptionDTO
|
||||
} & AdditionalData
|
||||
|
||||
type WorkflowInput = UpdateProductOptionsStepInput
|
||||
|
||||
export const updateProductOptionsWorkflowId = "update-product-options"
|
||||
/**
|
||||
* This workflow updates product options matching the specified filters.
|
||||
*/
|
||||
export const updateProductOptionsWorkflow = createWorkflow(
|
||||
updateProductOptionsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateProductOptionsWorkflowInput>) => {
|
||||
const updatedProductOptions = updateProductOptionsStep(input)
|
||||
const productOptionsUpdated = createHook("productOptionsUpdated", {
|
||||
product_options: updatedProductOptions,
|
||||
|
||||
@@ -7,17 +7,18 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { updateProductTagsStep } from "../steps"
|
||||
|
||||
type UpdateProductTagsStepInput = {
|
||||
export type UpdateProductTagsWorkflowInput = {
|
||||
selector: ProductTypes.FilterableProductTypeProps
|
||||
update: ProductTypes.UpdateProductTypeDTO
|
||||
} & AdditionalData
|
||||
|
||||
type WorkflowInput = UpdateProductTagsStepInput
|
||||
|
||||
export const updateProductTagsWorkflowId = "update-product-tags"
|
||||
/**
|
||||
* This workflow updates product tags matching the specified filters.
|
||||
*/
|
||||
export const updateProductTagsWorkflow = createWorkflow(
|
||||
updateProductTagsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateProductTagsWorkflowInput>) => {
|
||||
const updatedProductTags = updateProductTagsStep(input)
|
||||
const productTagsUpdated = createHook("productTagsUpdated", {
|
||||
product_tags: updatedProductTags,
|
||||
|
||||
@@ -7,17 +7,18 @@ import {
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { updateProductTypesStep } from "../steps"
|
||||
|
||||
type UpdateProductTypesStepInput = {
|
||||
type UpdateProductTypesWorkflowInput = {
|
||||
selector: ProductTypes.FilterableProductTypeProps
|
||||
update: ProductTypes.UpdateProductTypeDTO
|
||||
} & AdditionalData
|
||||
|
||||
type WorkflowInput = UpdateProductTypesStepInput
|
||||
|
||||
export const updateProductTypesWorkflowId = "update-product-types"
|
||||
/**
|
||||
* This workflow updates product types matching the specified filters.
|
||||
*/
|
||||
export const updateProductTypesWorkflow = createWorkflow(
|
||||
updateProductTypesWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateProductTypesWorkflowInput>) => {
|
||||
const updatedProductTypes = updateProductTypesStep(input)
|
||||
const productTypesUpdated = createHook("productTypesUpdated", {
|
||||
product_types: updatedProductTypes,
|
||||
|
||||
@@ -10,7 +10,7 @@ import { updateProductVariantsStep } from "../steps"
|
||||
import { updatePriceSetsStep } from "../../pricing"
|
||||
import { getVariantPricingLinkStep } from "../steps/get-variant-pricing-link"
|
||||
|
||||
type UpdateProductVariantsStepInput =
|
||||
export type UpdateProductVariantsWorkflowInput =
|
||||
| {
|
||||
selector: ProductTypes.FilterableProductVariantProps
|
||||
update: ProductTypes.UpdateProductVariantDTO & {
|
||||
@@ -23,12 +23,13 @@ type UpdateProductVariantsStepInput =
|
||||
})[]
|
||||
}
|
||||
|
||||
type WorkflowInput = UpdateProductVariantsStepInput & AdditionalData
|
||||
|
||||
export const updateProductVariantsWorkflowId = "update-product-variants"
|
||||
/**
|
||||
* This workflow updates one or more product variants.
|
||||
*/
|
||||
export const updateProductVariantsWorkflow = createWorkflow(
|
||||
updateProductVariantsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateProductVariantsWorkflowInput & AdditionalData>) => {
|
||||
// Passing prices to the product module will fail, we want to keep them for after the variant is updated.
|
||||
const updateWithoutPrices = transform({ input }, (data) => {
|
||||
if ("product_variants" in data.input) {
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from "../../common"
|
||||
import { upsertVariantPricesWorkflow } from "./upsert-variant-prices"
|
||||
|
||||
type UpdateProductsStepInputSelector = {
|
||||
export type UpdateProductsWorkflowInputSelector = {
|
||||
selector: ProductTypes.FilterableProductProps
|
||||
update: Omit<ProductTypes.UpdateProductDTO, "variants"> & {
|
||||
sales_channels?: { id: string }[]
|
||||
@@ -29,24 +29,22 @@ type UpdateProductsStepInputSelector = {
|
||||
}
|
||||
} & AdditionalData
|
||||
|
||||
type UpdateProductsStepInputProducts = {
|
||||
export type UpdateProductsWorkflowInputProducts = {
|
||||
products: (Omit<ProductTypes.UpsertProductDTO, "variants"> & {
|
||||
sales_channels?: { id: string }[]
|
||||
variants?: UpdateProductVariantWorkflowInputDTO[]
|
||||
})[]
|
||||
} & AdditionalData
|
||||
|
||||
type UpdateProductsStepInput =
|
||||
| UpdateProductsStepInputSelector
|
||||
| UpdateProductsStepInputProducts
|
||||
|
||||
type WorkflowInput = UpdateProductsStepInput
|
||||
export type UpdateProductWorkflowInput =
|
||||
| UpdateProductsWorkflowInputSelector
|
||||
| UpdateProductsWorkflowInputProducts
|
||||
|
||||
function prepareUpdateProductInput({
|
||||
input,
|
||||
}: {
|
||||
input: WorkflowInput
|
||||
}): UpdateProductsStepInput {
|
||||
input: UpdateProductWorkflowInput
|
||||
}): UpdateProductWorkflowInput {
|
||||
if ("products" in input) {
|
||||
if (!input.products.length) {
|
||||
return { products: [] }
|
||||
@@ -82,7 +80,7 @@ function updateProductIds({
|
||||
input,
|
||||
}: {
|
||||
updatedProducts: ProductTypes.ProductDTO[]
|
||||
input: WorkflowInput
|
||||
input: UpdateProductWorkflowInput
|
||||
}) {
|
||||
let productIds = updatedProducts.map((p) => p.id)
|
||||
|
||||
@@ -101,7 +99,7 @@ function prepareSalesChannelLinks({
|
||||
updatedProducts,
|
||||
}: {
|
||||
updatedProducts: ProductTypes.ProductDTO[]
|
||||
input: WorkflowInput
|
||||
input: UpdateProductWorkflowInput
|
||||
}): Record<string, Record<string, any>>[] {
|
||||
if ("products" in input) {
|
||||
if (!input.products.length) {
|
||||
@@ -143,7 +141,7 @@ function prepareVariantPrices({
|
||||
updatedProducts,
|
||||
}: {
|
||||
updatedProducts: ProductTypes.ProductDTO[]
|
||||
input: WorkflowInput
|
||||
input: UpdateProductWorkflowInput
|
||||
}): {
|
||||
variant_id: string
|
||||
product_id: string
|
||||
@@ -209,9 +207,12 @@ function prepareToDeleteSalesChannelLinks({
|
||||
}
|
||||
|
||||
export const updateProductsWorkflowId = "update-products"
|
||||
/**
|
||||
* This workflow updates one or more products.
|
||||
*/
|
||||
export const updateProductsWorkflow = createWorkflow(
|
||||
updateProductsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>) => {
|
||||
(input: WorkflowData<UpdateProductWorkflowInput>) => {
|
||||
// We only get the variant ids of products that are updating the variants and prices.
|
||||
const variantIdsSelector = transform({ input }, (data) => {
|
||||
if ("products" in data.input) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import { removeRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
||||
import { createPriceSetsStep, updatePriceSetsStep } from "../../pricing"
|
||||
import { createVariantPricingLinkStep } from "../steps"
|
||||
|
||||
type WorkflowInput = {
|
||||
export type UpsertVariantPricesWorkflowInput = {
|
||||
variantPrices: {
|
||||
variant_id: string
|
||||
product_id: string
|
||||
@@ -23,9 +23,12 @@ type WorkflowInput = {
|
||||
}
|
||||
|
||||
export const upsertVariantPricesWorkflowId = "upsert-variant-prices"
|
||||
/**
|
||||
* This workflow creates or updates variants' prices.
|
||||
*/
|
||||
export const upsertVariantPricesWorkflow = createWorkflow(
|
||||
upsertVariantPricesWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
|
||||
(input: WorkflowData<UpsertVariantPricesWorkflowInput>): WorkflowData<void> => {
|
||||
const removedVariantIds = transform({ input }, (data) => {
|
||||
return arrayDifference(
|
||||
data.input.previousVariantIds,
|
||||
|
||||
Reference in New Issue
Block a user