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,medusa,types): cancel fulfillments API #7095

Merged
merged 7 commits into from
Apr 18, 2024

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Apr 18, 2024

what:

  • adds POST cancel fulfillments endpoint

RESOLVES CORE-1972

Copy link

changeset-bot bot commented Apr 18, 2024

🦋 Changeset detected

Latest commit: dd49bdc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@medusajs/core-flows Patch
@medusajs/medusa Patch
@medusajs/types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 18, 2024 10:46am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Apr 18, 2024 10:46am
docs-ui ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2024 10:46am
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Apr 18, 2024 10:46am

MedusaResponse,
} from "../../../../types/routing"

export const DELETE = async (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@olivermrbl since we're not exposing delete for fulfillment in the module, am i right in assuming that this is a cancel endpoint? If so, wouldn't it make more sense to call this POST /admin/fulfillments/:id/cancel?

Copy link
Member

Choose a reason for hiding this comment

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

I think that makes sense, since we are not deleting anything here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, makes sense 👍

MedusaResponse,
} from "../../../../types/routing"

export const DELETE = async (
Copy link
Member

Choose a reason for hiding this comment

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

I think that makes sense, since we are not deleting anything here.

ModuleRegistrationName.FULFILLMENT
)

await fulfillmentModuleService.retrieveFulfillment(id)
Copy link
Member

Choose a reason for hiding this comment

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

Is this only for validation? If so, I'd suggest we do it in the workflow instead

Copy link
Contributor

Choose a reason for hiding this comment

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

I have come across a similar case a few times, and I can't figure out what the right thing to do is, so maybe we should establish a convention.

Typically, our workflows expect a specific shape of data for bulk mutating a resource and therefore do not have validation built-in – as they would have in the case of a single mutation through retrieve. Given that our HTTP layer almost always operates on a single (root) resource, one could argue the validation is well-placed in the controller.

E.g. right now, sending a request to update a product with an ID that does not exist will perform a selector-based update. There is not a product to update, so the return value of the workflow in an empty array and the subsequent call to fetch the product fails.

Copy link
Member

Choose a reason for hiding this comment

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

@olivermrbl you have a point due to the fact that we do a select-based mutation. My thought-process is that workflows should validate that what they are operating on is correct, since they can be executed from a non-http flow, but in this specific scenario I can see why it might make sense to do the validation here, cc @riqwan WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its a moot point for this endpoint since the module internally calls retrieveFulfillment to validate its existence.

I agree that the validation generally being on the workflow makes total sense as its built to run independently, but running validations on the endpoint is also totally valid in cases where the endpoint needs to have agency over its job of rendering the response graciously and consistently.

Copy link
Member

Choose a reason for hiding this comment

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

The only aspect to consider here is to not fire 3-4 DB requests for just checking if something exists, which is why I suggested moving the check elsewhere. Ideally the HTTP endpoint can "clean up" the response in a purely synchronous manner, but I agree that there might be times where an async call to some endpoint is needed for a better response.

Anyhow, it's not too important for now, but these are considerations we'll need to make as we make v2.0 more prod-ready

ModuleRegistrationName.FULFILLMENT
)

await promiseAll(ids.map((id) => service.cancelFulfillment(id)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@olivermrbl this looks like a non reversible step. Should we remove bulk capabilities here if that is the case?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense, nice catch. We should treat all steps that interface with 3rd party providers this way – as we did with payments already. So bulk operations would have to be handled "manually" by the consumer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice, changed em!

Copy link
Contributor

@olivermrbl olivermrbl left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit 62b9dcc into develop Apr 18, 2024
24 checks passed
@kodiakhq kodiakhq bot deleted the feat/fulfillment-delete branch April 18, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants