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
4 changes: 2 additions & 2 deletions src/categories/category.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class CategoryService {
? await queryRunnerManager.findOneOrFail(Category, {
where: { id: category.parentId },
})
: undefined;
: null;

// find children categories
const childrenCategories = await queryRunnerManager.find(Category, {
Expand Down Expand Up @@ -522,7 +522,7 @@ You can only answer a single category name. Here is the article's information:
}</description>
<siteName>${siteName && `site name: "${siteName.trim()}"`}</siteName>

Given the categories below, please provide the most suitable category for the article following the rules.
Given the categories below, please provide suitable category for the article following the rules.
[RULES]
- The deeper the category depth, the more specific the category is.
- If the 1, 2, and 3 depth categories are equally worthy of saving links, then the deeper categories should be recommended more.
Expand Down
50 changes: 29 additions & 21 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class ContentsService {
}

if (contentLinks.length > 0) {
let category: Category | undefined = undefined;
let category: Category | null = null;
if (categoryName) {
category = await this.categoryRepository.getOrCreateCategory(
categoryName,
Expand Down Expand Up @@ -183,6 +183,7 @@ export class ContentsService {
comment,
reminder,
favorite,
categoryId,
categoryName,
parentId,
}: UpdateContentBodyDto,
Expand Down Expand Up @@ -210,31 +211,38 @@ export class ContentsService {
throw new NotFoundException('Content not found.');
}

let category: Category | undefined = undefined;
if (categoryName) {
category = await this.categoryRepository.getOrCreateCategory(
categoryName,
parentId,
userInDb,
if (categoryId !== undefined) {
const category =
categoryId !== null
? await this.categoryRepository.findById(categoryId, entityManager)
: null;

if (category) {
await checkContentDuplicateAndAddCategorySaveLog(
link,
category,
userInDb,
);
}

await this.contentRepository.updateOne(
{
id: content.id,
...newContentObj,
category,
},
entityManager,
);

await checkContentDuplicateAndAddCategorySaveLog(
link,
category,
userInDb,
} else {
await this.contentRepository.updateOne(
{
id: content.id,
...newContentObj,
},
entityManager,
);
}

await this.contentRepository.updateOne(
{
id: content.id,
...newContentObj,
category,
},
entityManager,
);

return {};
}

Expand Down
6 changes: 6 additions & 0 deletions src/contents/dtos/content.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export class AddMultipleContentsBodyDto {
@IsOptional()
categoryName?: string;

@ApiProperty({ description: '카테고리 id', required: false })
@IsInt()
@IsPositive()
@IsOptional()
categoryId?: number;

@ApiProperty({
description: '부모 카테고리 id',
example: 1,
Expand Down
13 changes: 10 additions & 3 deletions src/contents/entities/content.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,20 @@ export class Content extends CoreEntity {
@IsBoolean()
favorite?: boolean;

@ApiProperty({ description: 'Article Category', required: false })
@ApiProperty({
description: 'Article Category',
required: false,
default: null,
})
@ManyToOne(() => Category, (category) => category.contents, {
nullable: true,
onDelete: 'SET NULL',
})
@JoinColumn({ name: 'categoryId', referencedColumnName: 'id' })
category?: Category;
@JoinColumn({
name: 'categoryId',
referencedColumnName: 'id',
})
category: Category | null;

@ManyToOne(() => User, (user) => user.contents, {
onDelete: 'CASCADE',
Expand Down
Loading