feat(medusa): added admin create endpoint for nested categories (#2985)

What:

Introduces an admin endpoint that allows a user to create a product category

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 create category
- Creates a method in product category services to create a category

RESOLVES CORE-958
This commit is contained in:
Riqwan Thamir
2023-01-11 14:29:02 +01:00
committed by GitHub
parent 39c3513b2c
commit 8ed4eab73a
8 changed files with 297 additions and 7 deletions
@@ -1,5 +1,6 @@
import { generateEntityId } from "../utils/generate-entity-id"
import { SoftDeletableEntity } from "../interfaces/models/soft-deletable-entity"
import { kebabCase } from "lodash"
import {
BeforeInsert,
Index,
@@ -41,7 +42,7 @@ export class ProductCategory extends SoftDeletableEntity {
// Typeorm also keeps track of the category's parent at all times.
@Column()
parent_category_id: ProductCategory
parent_category_id: string | null
@TreeChildren({ cascade: true })
category_children: ProductCategory[]
@@ -49,6 +50,10 @@ export class ProductCategory extends SoftDeletableEntity {
@BeforeInsert()
private beforeInsert(): void {
this.id = generateEntityId(this.id, "pcat")
if (!this.handle) {
this.handle = kebabCase(this.name)
}
}
}
@@ -60,7 +65,6 @@ export class ProductCategory extends SoftDeletableEntity {
* type: object
* required:
* - name
* - handle
* properties:
* id:
* type: string