-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Conversation
🦋 Changeset detectedLatest commit: 4a0a731 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
There was a problem hiding this 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/api/routes/admin/product-categories/delete-product-category.ts
Outdated
Show resolved
Hide resolved
IdMap.getId("jeans") | ||
) | ||
|
||
expect(productCategoryRepository.softRemove).toBeCalledTimes(1) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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
There was a problem hiding this 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! 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this 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
3e6b94c
to
8ed911b
Compare
) | ||
} | ||
|
||
await productCategoryRepository.softRemove(productCategory) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
const productCategory = await this.retrieve(productCategoryId, { | ||
relations: ["category_children"], | ||
}) |
There was a problem hiding this comment.
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
const productCategory = await this.retrieve(productCategoryId, { | |
relations: ["category_children"], | |
}) | |
const productCategory = await this.retrieve(productCategoryId, { | |
relations: ["category_children"], | |
}).catch(err => void 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.catch(() => void 0)
10e1440
to
904b218
Compare
904b218
to
2a32017
Compare
2a32017
to
c16773b
Compare
There was a problem hiding this 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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two minor comments
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:
RESOLVES CORE-957