Skip to content

Commit

Permalink
Merge pull request #308 from Quickchive/fix/#307-make-parent-id-null
Browse files Browse the repository at this point in the history
Fix/#307 make parent id null
  • Loading branch information
stae1102 authored Mar 10, 2024
2 parents 4d67d3f + b480015 commit d8a80e4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/categories/category.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/categories/category.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class CategoryRepository extends Repository<Category> {
}

async createOne(
category: Category & { parentId?: number },
category: Category & { parentId?: number | null },
entityManager?: EntityManager,
): Promise<Category> {
return entityManager ? entityManager?.save(category) : this.save(category);
Expand Down
3 changes: 2 additions & 1 deletion src/categories/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
);
Expand Down

0 comments on commit d8a80e4

Please sign in to comment.