feat(medusa): categories can be ranked based on position (#3341)

* chore: categories can be ranked based on position

* chore: fix tests

* chore: sort categories by order

* chore: fix bug where mpath relationship is messed up

* chore: enable linting - lint changes

* Update packages/medusa/src/repositories/product-category.ts

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>

* chore: fixed specs

* chore: cleanup repository to new typeorm interfaces + cleanup

* chore: revert repository changes due to incorrect sql

* chore: addressed pr reviews

---------

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
This commit is contained in:
Riqwan Thamir
2023-03-06 15:49:16 +01:00
committed by GitHub
parent 67ba8be02b
commit 0a6aa0e624
16 changed files with 986 additions and 167 deletions
@@ -144,6 +144,7 @@ export const defaultProductCategoryFields = [
"handle",
"is_active",
"is_internal",
"rank",
"parent_category_id",
"created_at",
"updated_at",
@@ -1,9 +1,10 @@
import { IsOptional, IsString } from "class-validator"
import { IsOptional, IsString, IsBoolean } from "class-validator"
import { Request, Response } from "express"
import { Transform } from "class-transformer"
import { ProductCategoryService } from "../../../../services"
import { extendedFindParamsMixin } from "../../../../types/common"
import { optionalBooleanMapper } from "../../../../utils/validators/is-boolean"
/**
* @oas [get] /admin/product-categories
@@ -93,8 +94,9 @@ export class AdminGetProductCategoriesParams extends extendedFindParamsMixin({
@IsOptional()
q?: string
@IsString()
@IsBoolean()
@IsOptional()
@Transform(({ value }) => optionalBooleanMapper.get(value))
include_descendants_tree?: boolean
@IsString()
@@ -1,4 +1,4 @@
import { IsOptional, IsString } from "class-validator"
import { IsOptional, IsString, IsInt, Min, IsNotEmpty } from "class-validator"
import { Request, Response } from "express"
import { EntityManager } from "typeorm"
@@ -115,12 +115,21 @@ export default async (req: Request, res: Response) => {
* parent_category_id:
* type: string
* description: The ID of the parent product category
* rank:
* type: number
* description: The rank of the category in the tree node (starting from 0)
*/
// eslint-disable-next-line max-len
export class AdminPostProductCategoriesCategoryReq extends AdminProductCategoriesReqBase {
@IsString()
@IsOptional()
name?: string
@IsOptional()
@IsInt()
@IsNotEmpty()
@Min(0)
rank?: number
}
export class AdminPostProductCategoriesCategoryParams extends FindParams {}
@@ -58,6 +58,7 @@ export const defaultStoreProductCategoryFields = [
"parent_category_id",
"created_at",
"updated_at",
"rank",
]
export const allowedStoreProductCategoryFields = [
@@ -67,6 +68,7 @@ export const allowedStoreProductCategoryFields = [
"parent_category_id",
"created_at",
"updated_at",
"rank",
]
/**