From b480015d0b98c9d52baa9fb93eeb8238d942aa4e Mon Sep 17 00:00:00 2001 From: stae1102 Date: Sun, 10 Mar 2024 21:05:18 +0900 Subject: [PATCH] feat: delete parentId whenever children become parent --- src/categories/category.service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; }), );