From accb20c7d7b01f954acc2b9506e8d32bc8e1812b Mon Sep 17 00:00:00 2001 From: stae1102 Date: Sun, 27 Jul 2025 16:20:30 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=BD=98=ED=85=90=EC=B8=A0=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=20=EC=8B=9C=EC=97=90=EB=8F=84=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=A4=91=EB=B3=B5=EA=B2=80=EC=82=AC=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/contents/contents.service.ts | 34 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/contents/contents.service.ts b/src/contents/contents.service.ts index 48f18789..582a6ec 100644 --- a/src/contents/contents.service.ts +++ b/src/contents/contents.service.ts @@ -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; @@ -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, @@ -495,6 +497,8 @@ export class ContentsService { }, }); - return existingContents.length > 0; + if (existingContents.length > 0) { + throw new ConflictException('이미 저장된 컨텐츠입니다.'); + } } }