feat: Align the product module HTTP API to follow our conventions (#6759)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ILinkModule } from "@medusajs/types"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
@@ -11,23 +10,15 @@ export const removeVariantPricingLinkStepId = "remove-variant-pricing-link"
|
||||
export const removeVariantPricingLinkStep = createStep(
|
||||
removeVariantPricingLinkStepId,
|
||||
async (data: StepInput, { container }) => {
|
||||
if (!data.variant_ids.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||
const linkModule: ILinkModule = remoteLink.getLinkModule(
|
||||
Modules.PRODUCT,
|
||||
"variant_id",
|
||||
Modules.PRICING,
|
||||
"price_set_id"
|
||||
)
|
||||
|
||||
const links = (await linkModule.list(
|
||||
{
|
||||
variant_id: data.variant_ids,
|
||||
},
|
||||
{ select: ["id", "variant_id", "price_set_id"] }
|
||||
)) as { id: string; variant_id: string; price_set_id: string }[]
|
||||
|
||||
await remoteLink.delete(links.map((link) => link.id))
|
||||
return new StepResponse(void 0, links)
|
||||
await remoteLink.delete({
|
||||
[Modules.PRODUCT]: { variant_id: data.variant_ids },
|
||||
})
|
||||
return new StepResponse(void 0, data.variant_ids)
|
||||
},
|
||||
async (prevData, { container }) => {
|
||||
if (!prevData?.length) {
|
||||
@@ -35,15 +26,8 @@ export const removeVariantPricingLinkStep = createStep(
|
||||
}
|
||||
|
||||
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)
|
||||
await remoteLink.create(
|
||||
prevData.map((entry) => ({
|
||||
[Modules.PRODUCT]: {
|
||||
variant_id: entry.variant_id,
|
||||
},
|
||||
[Modules.PRICING]: {
|
||||
price_set_id: entry.price_set_id,
|
||||
},
|
||||
}))
|
||||
)
|
||||
await remoteLink.restore({
|
||||
[Modules.PRODUCT]: { variant_id: prevData },
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -10,7 +10,6 @@ export const deleteProductVariantsWorkflowId = "delete-product-variants"
|
||||
export const deleteProductVariantsWorkflow = createWorkflow(
|
||||
deleteProductVariantsWorkflowId,
|
||||
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
|
||||
// Question: Should we also remove the price set manually, or would that be cascaded?
|
||||
removeVariantPricingLinkStep({ variant_ids: input.ids })
|
||||
return deleteProductVariantsStep(input.ids)
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ export const deleteProductsWorkflow = createWorkflow(
|
||||
.map((variant) => variant.id)
|
||||
})
|
||||
|
||||
// Question: Should we also remove the price set manually, or would that be cascaded?
|
||||
// Question: Since we soft-delete the product, how do we restore the product with the prices and the links?
|
||||
removeVariantPricingLinkStep({ variant_ids: variantsToBeDeleted })
|
||||
|
||||
return deleteProductsStep(input.ids)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user