@@ -87,17 +87,23 @@ export class ContentsService {
8787 const content = new Content ( ) ;
8888
8989 if ( categoryId ) {
90- const category = await this . categoryRepository . findById (
91- categoryId ,
92- entityManager ,
93- ) ;
90+ const [ category , subCategories ] = await Promise . all ( [
91+ ( async ( ) => {
92+ const category = await this . categoryRepository . findById ( categoryId ) ;
9493
95- if ( ! category ) throw new NotFoundException ( 'Category not found' ) ;
94+ if ( ! category ) {
95+ throw new NotFoundException ( '카테고리가 존재하지 않습니다.' ) ;
96+ }
9697
97- await checkContentDuplicateAndAddCategorySaveLog (
98- link ,
99- category ,
100- userInDb ,
98+ return category ;
99+ } ) ( ) ,
100+ this . categoryRepository . findByParentId ( categoryId ) ,
101+ ] ) ;
102+
103+ await this . isDuplicatedContents (
104+ content . id ,
105+ [ category , ...subCategories ] ,
106+ content . link ,
101107 ) ;
102108
103109 content . category = category ;
@@ -223,16 +229,12 @@ export class ContentsService {
223229 this . categoryRepository . findByParentId ( categoryId ) ,
224230 ] ) ;
225231
226- const isDuplicated = await this . isDuplicatedContents (
232+ await this . isDuplicatedContents (
227233 content . id ,
228234 [ category , ...subCategories ] ,
229235 content . link ,
230236 ) ;
231237
232- if ( isDuplicated ) {
233- throw new ConflictException ( '이미 저장된 컨텐츠입니다.' ) ;
234- }
235-
236238 await this . contentRepository . updateOne (
237239 {
238240 id : content . id ,
@@ -495,6 +497,8 @@ export class ContentsService {
495497 } ,
496498 } ) ;
497499
498- return existingContents . length > 0 ;
500+ if ( existingContents . length > 0 ) {
501+ throw new ConflictException ( '이미 저장된 컨텐츠입니다.' ) ;
502+ }
499503 }
500504}
0 commit comments