Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -624,6 +626,8 @@ export class CategoryService {

/**
* 자식 카테고리가 있는 경우, 부모 카테고리와 연결
* 단, 삭제되는 카테고리가 1단 카테고리인 경우 부모 카테고리가 없으므로
* 자식 카테고리의 부모 카테고리를 null로 설정
*/

// find parent category
Expand All @@ -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;
}),
);
Expand Down
4 changes: 2 additions & 2 deletions src/contents/entities/category.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion src/contents/repository/category.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class CategoryRepository extends Repository<Category> {
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
Expand Down