Skip to content
Merged
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
34 changes: 19 additions & 15 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,23 @@ export class ContentsService {
const content = new Content();

if (categoryId) {
const category = await this.categoryRepository.findById(
categoryId,
entityManager,
);
const [category, subCategories] = await Promise.all([
(async () => {
const category = await this.categoryRepository.findById(categoryId);

if (!category) throw new NotFoundException('Category not found');
if (!category) {
throw new NotFoundException('카테고리가 존재하지 않습니다.');
}

await checkContentDuplicateAndAddCategorySaveLog(
link,
category,
userInDb,
return category;
})(),
this.categoryRepository.findByParentId(categoryId),
]);

await this.isDuplicatedContents(
content.id,
[category, ...subCategories],
content.link,
);

content.category = category;
Expand Down Expand Up @@ -223,16 +229,12 @@ export class ContentsService {
this.categoryRepository.findByParentId(categoryId),
]);

const isDuplicated = await this.isDuplicatedContents(
await this.isDuplicatedContents(
content.id,
[category, ...subCategories],
content.link,
);

if (isDuplicated) {
throw new ConflictException('이미 저장된 컨텐츠입니다.');
}

await this.contentRepository.updateOne(
{
id: content.id,
Expand Down Expand Up @@ -495,6 +497,8 @@ export class ContentsService {
},
});

return existingContents.length > 0;
if (existingContents.length > 0) {
throw new ConflictException('이미 저장된 컨텐츠입니다.');
}
}
}