Skip to content

Commit

Permalink
chore: address review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan committed Feb 22, 2023
1 parent f9b4669 commit b3573b2
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions packages/medusa/src/services/product-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ProductCategoryService extends TransactionBaseService {
return await this.atomicPhase_(async (manager) => {
const pcRepo = manager.withRepository(this.productCategoryRepo_)

await this.transformParentIdToEntity_(productCategoryInput, pcRepo)
await this.transformParentIdToEntity(productCategoryInput)

let productCategory = pcRepo.create(productCategoryInput)
productCategory = await pcRepo.save(productCategory)
Expand Down Expand Up @@ -160,10 +160,7 @@ class ProductCategoryService extends TransactionBaseService {
this.productCategoryRepo_
)

await this.transformParentIdToEntity_(
productCategoryInput,
productCategoryRepo
)
await this.transformParentIdToEntity(productCategoryInput)

let productCategory = await this.retrieve(productCategoryId)

Expand Down Expand Up @@ -266,14 +263,12 @@ class ProductCategoryService extends TransactionBaseService {
* Accepts an input object and transforms product_category_id
* into product_category entity.
* @param productCategoryInput - params used to create/update
* @param {repository} A repository to query entity from
* @return transformed productCategoryInput
*/
protected async transformParentIdToEntity_(
protected async transformParentIdToEntity(
productCategoryInput:
| CreateProductCategoryInput
| UpdateProductCategoryInput,
repository: typeof ProductCategoryRepository
| UpdateProductCategoryInput
): Promise<CreateProductCategoryInput | UpdateProductCategoryInput> {
// Typeorm only updates mpath when the category entity of the parent
// is passed into create/save. For this reason, everytime we create a
Expand All @@ -284,9 +279,7 @@ class ProductCategoryService extends TransactionBaseService {
return productCategoryInput
}

const parentCategory = await repository.findOne(
buildQuery({ id: parentCategoryId }, {})
)
const parentCategory = await this.retrieve(parentCategoryId)

productCategoryInput.parent_category = parentCategory
delete productCategoryInput.parent_category_id
Expand Down

0 comments on commit b3573b2

Please sign in to comment.