diff --git a/src/categories/category.entity.ts b/src/categories/category.entity.ts index 7f8be89..f8332cf 100644 --- a/src/categories/category.entity.ts +++ b/src/categories/category.entity.ts @@ -47,7 +47,7 @@ export class Category extends CoreEntity { @ApiProperty({ description: 'Category Parent ID', example: 1, type: Number }) @Column({ type: 'int', nullable: true }) - parentId?: number; + parentId?: number | null; @ManyToOne(() => User, (user) => user.categories, { onDelete: 'CASCADE', diff --git a/src/categories/category.repository.ts b/src/categories/category.repository.ts index ff6abd9..0e1db69 100644 --- a/src/categories/category.repository.ts +++ b/src/categories/category.repository.ts @@ -24,7 +24,7 @@ export class CategoryRepository extends Repository { } async createOne( - category: Category & { parentId?: number }, + category: Category & { parentId?: number | null }, entityManager?: EntityManager, ): Promise { return entityManager ? entityManager?.save(category) : this.save(category); diff --git a/src/categories/category.service.ts b/src/categories/category.service.ts index 03db16d..d7698ec 100644 --- a/src/categories/category.service.ts +++ b/src/categories/category.service.ts @@ -244,11 +244,12 @@ export class CategoryService { // find children categories const childrenCategories = await queryRunnerManager.find(Category, { where: { parentId: categoryId }, + order: { createdAt: 'DESC' }, }); await queryRunnerManager.save( childrenCategories.map((childrenCategory) => { - childrenCategory.parentId = parentCategory?.id; + childrenCategory.parentId = parentCategory?.id ?? null; return childrenCategory; }), );