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(medusa): Nested Categories Admin Delete Endpoint #2975

Merged
merged 23 commits into from
Jan 10, 2023

Conversation

riqwan
Copy link
Contributor

@riqwan riqwan commented Jan 10, 2023

What:

Introduces an admin endpoint that allows a user to delete a product category, given an ID.

Why:

This is part of a greater goal of allowing products to be added to multiple categories.

How:

  • Creates a route on the admin scope to delete category
  • Creates a method in product category services to delete a category

RESOLVES CORE-957

@changeset-bot
Copy link

changeset-bot bot commented Jan 10, 2023

🦋 Changeset detected

Latest commit: 4a0a731

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

This PR includes changesets to release 1 package
Name Type
@medusajs/medusa 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

@riqwan riqwan marked this pull request as ready for review January 10, 2023 07:21
@riqwan riqwan requested a review from a team as a code owner January 10, 2023 07:21
Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

Nice work 🎉

packages/medusa/src/services/product-category.ts Outdated Show resolved Hide resolved
IdMap.getId("jeans")
)

expect(productCategoryRepository.softRemove).toBeCalledTimes(1)
Copy link
Member

Choose a reason for hiding this comment

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

question: I am wondering if it make sense to softRemove a category? Is it to allow a user to recover it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No particular reason here. Just following the same methods as what other similar resources are doing (sales channels, product collection, etc.)

Copy link
Member

Choose a reason for hiding this comment

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

My question is more about, should a category be soft deletable?

cc @olivermrbl

packages/medusa/src/services/product-category.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@pKorsholm pKorsholm left a comment

Choose a reason for hiding this comment

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

Very nice! I really like the thoroughness of the tests!

I have a comment regarding idempotent deletes as a convention, but otherwise I have no comments, it looks great! 😄

Base automatically changed from feat/nested-category-get-endpoint to develop January 10, 2023 09:08
@riqwan riqwan requested review from adrien2p and pKorsholm January 10, 2023 09:49
Copy link
Collaborator

@srindom srindom left a comment

Choose a reason for hiding this comment

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

LGTM!

@riqwan riqwan changed the title feat(medusa): added delete endpoint for categories feat(medusa): Nested Categories Admin Delete Endpoint Jan 10, 2023
Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

LGTM, just one change to make before merging

packages/medusa/src/services/product-category.ts Outdated Show resolved Hide resolved
@riqwan riqwan force-pushed the feat/nested-category-delete-endpoint branch from 3e6b94c to 8ed911b Compare January 10, 2023 11:00
)
}

await productCategoryRepository.softRemove(productCategory)
Copy link
Contributor

Choose a reason for hiding this comment

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

comment(non-blocking): Bringing the discussion down here @adrien2p, we should be able to hard-delete categories, as we don't benefit from any of the usual advantages that come from soft-deletion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this to hard delete.

Comment on lines 80 to 82
const productCategory = await this.retrieve(productCategoryId, {
relations: ["category_children"],
})
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: Retrieve will throw on non-existing categories, so to resolve idempotently we should catch the error and return undefined

Suggested change
const productCategory = await this.retrieve(productCategoryId, {
relations: ["category_children"],
})
const productCategory = await this.retrieve(productCategoryId, {
relations: ["category_children"],
}).catch(err => void 0)

Copy link
Member

Choose a reason for hiding this comment

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

.catch(() => void 0)

@riqwan riqwan force-pushed the feat/nested-category-delete-endpoint branch 2 times, most recently from 10e1440 to 904b218 Compare January 10, 2023 12:24
@riqwan riqwan requested a review from olivermrbl January 10, 2023 12:31
@riqwan riqwan force-pushed the feat/nested-category-delete-endpoint branch from 904b218 to 2a32017 Compare January 10, 2023 12:36
@riqwan riqwan force-pushed the feat/nested-category-delete-endpoint branch from 2a32017 to c16773b Compare January 10, 2023 12:36
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!


const productCategory = await this.retrieve(productCategoryId, {
relations: ["category_children"],
}).catch((err) => void 0)
Copy link
Member

Choose a reason for hiding this comment

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

non blocking: remove err


await productCategoryRepository.delete(productCategory.id)

return Promise.resolve()
Copy link
Member

@adrien2p adrien2p Jan 10, 2023

Choose a reason for hiding this comment

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

todo: remove, async already wrap in a promise

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

two minor comments

@kodiakhq kodiakhq bot merged commit 71fa608 into develop Jan 10, 2023
@kodiakhq kodiakhq bot deleted the feat/nested-category-delete-endpoint branch January 10, 2023 14:28
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.

5 participants