Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core-flows): Use remote link methods to dismiss all links related to inventory item #6737

Merged
merged 6 commits into from
Mar 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,21 @@ export const deatachInventoryItemStep = createStep(
async (ids: string[], { container }) => {
const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)

const linkModule: ILinkModule = remoteLink.getLinkModule(
Modules.PRODUCT,
"variant_id",
Modules.INVENTORY,
"inventory_item_id"
)
await remoteLink.delete({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, didn't know this does a soft delete. Would be good to have a test that checks this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: don't have to do this now, but I wonder if we can do a generic deleteLinkStep() that accepts an object. Something like this:

deleteLinkStep({
  [Modules.INVENTORY]: { inventory_item_id: data.ids },
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Modules.INVENTORY]: { inventory_item_id: ids },
})

const links = (await linkModule.list(
{ inventory_item_id: ids },
{ select: ["variant_id", "inventory_item_id"] }
)) as { inventory_item_id: string; variant_id: string }[]

await remoteLink.dismiss(
links.map(({ inventory_item_id, variant_id }) => ({
[Modules.PRODUCT]: {
variant_id,
},
[Modules.INVENTORY]: {
inventory_item_id,
},
}))
)

return new StepResponse(void 0, links)
return new StepResponse(void 0, ids)
},
async (input, { container }) => {
if (!input?.length) {
async (deatachedInventoryIds, { container }) => {
if (!deatachedInventoryIds?.length) {
return
}

const remoteLink = container.resolve(ContainerRegistrationKeys.REMOTE_LINK)

const linkDefinitions = input.map(({ inventory_item_id, variant_id }) => ({
[Modules.PRODUCT]: {
variant_id,
},
[Modules.INVENTORY]: {
inventory_item_id,
},
}))

const links = await remoteLink.create(linkDefinitions)
await remoteLink.restore({
[Modules.INVENTORY]: { inventory_item_id: deatachedInventoryIds },
})
}
)
Loading