From b58533ead7153c36c71b851c622361b119b14612 Mon Sep 17 00:00:00 2001 From: hou27 Date: Wed, 1 Nov 2023 17:42:25 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20category=EC=9D=98=20parentId=20type?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20-=20#211?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit parentId property에 null이 할당 가능하도록 postgres용 type과 typescript용 type을 각각 따로 명시 --- src/contents/entities/category.entity.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/contents/entities/category.entity.ts b/src/contents/entities/category.entity.ts index 0526a0c..5f89c89 100644 --- a/src/contents/entities/category.entity.ts +++ b/src/contents/entities/category.entity.ts @@ -26,8 +26,8 @@ export class Category extends CoreEntity { collections!: Collection[]; @ApiProperty({ description: 'Category Parent ID' }) - @Column({ nullable: true }) - parentId?: number; + @Column({ type: 'int', nullable: true }) + parentId?: number | null; @ManyToOne((type) => User, (user) => user.categories, { onDelete: 'CASCADE', From 132f36970b28d56da4fb07be2a6175ed85334d03 Mon Sep 17 00:00:00 2001 From: hou27 Date: Wed, 1 Nov 2023 17:45:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20parentId=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=88=98=EC=A0=95=20-=20#211?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contents/repository/category.repository.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/contents/repository/category.repository.ts b/src/contents/repository/category.repository.ts index 2f956a8..d84e48c 100644 --- a/src/contents/repository/category.repository.ts +++ b/src/contents/repository/category.repository.ts @@ -48,7 +48,9 @@ export class CategoryRepository extends Repository { if (i === 1 && parentCategory?.parentId !== null) { throw new ConflictException('Category depth should be 3'); } - currentParentId = parentCategory?.parentId; + if (parentCategory?.parentId) + currentParentId = parentCategory?.parentId; + else break; } } // check if category exists in user's categories From ef5da4b984f8b4cf89e4560396ce3dde043bff9c Mon Sep 17 00:00:00 2001 From: hou27 Date: Wed, 1 Nov 2023 17:46:01 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=82=AD=EC=A0=9C=20=EC=9E=91=EC=97=85=20=EC=A4=91?= =?UTF-8?q?=20parentCategory=EA=B0=80=20=EC=97=86=EC=9D=84=20=EB=95=8C=20?= =?UTF-8?q?=EB=8F=99=EC=9E=91=20=EC=88=98=EC=A0=95=20-=20#211?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 하위 카테고리가 있는 경우 삭제되는 카테고리의 부모 카테고리를 위임했었음. 이때 1단 카테고리기 때문에 부모 카테고리가 없는 경우 null을 할당하도록 함. --- src/contents/contents.service.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/contents/contents.service.ts b/src/contents/contents.service.ts index 0c61ae4..d345419 100644 --- a/src/contents/contents.service.ts +++ b/src/contents/contents.service.ts @@ -470,10 +470,12 @@ export class CategoryService { parentCategory = await queryRunnerManager.findOne(Category, { where: { id: currentParentId }, }); - if (i == 1 && parentCategory?.parentId != null) { + if (i == 1 && parentCategory?.parentId !== null) { throw new ConflictException('Category depth should be 3'); } - currentParentId = parentCategory?.parentId; + if (parentCategory?.parentId) + currentParentId = parentCategory?.parentId; + else break; } } else { /** @@ -624,6 +626,8 @@ export class CategoryService { /** * 자식 카테고리가 있는 경우, 부모 카테고리와 연결 + * 단, 삭제되는 카테고리가 1단 카테고리인 경우 부모 카테고리가 없으므로 + * 자식 카테고리의 부모 카테고리를 null로 설정 */ // find parent category @@ -638,10 +642,9 @@ export class CategoryService { where: { parentId: categoryId }, }); - // set children categories' parent to parent category await queryRunnerManager.save( childrenCategories.map((childrenCategory) => { - childrenCategory.parentId = parentCategory?.id; + childrenCategory.parentId = parentCategory?.id ?? null; return childrenCategory; }), );