From da52035dd93a8038420ae9422e732c22b10e03e5 Mon Sep 17 00:00:00 2001 From: jihwooon Date: Mon, 18 Dec 2023 14:15:59 +0900 Subject: [PATCH] =?UTF-8?q?item-image=EB=A5=BC=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=84=B0=EB=A6=AC=EC=9D=84=20=ED=95=98=EB=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit item-image 조건문 논리 연산자를 수정했습니다. && 보다는 || 로 변경해서 가독성을 높였습니다. Promise.all을 사용해서 file을 병렬처리 하도록 수정했습니다. --- .../item-images/application/item-image.creater.ts | 13 +++++++------ .../item-images/application/item-image.updater.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/src/item-images/application/item-image.creater.ts b/server/src/item-images/application/item-image.creater.ts index 45f32da..8e81e9c 100644 --- a/server/src/item-images/application/item-image.creater.ts +++ b/server/src/item-images/application/item-image.creater.ts @@ -13,15 +13,16 @@ export class ItemImageCreater { ) {} async saveItemImages(itemId: number, @UploadedFiles() files: Express.Multer.File[]) { - if (Array.isArray(files) && files.length === 0) { + if (!files || files.length === 0) { throw new FileIsNotEmpty('파일은 필수 입력 값입니다') } - files.map((file, i) => { - const isRepresentImage: boolean = i === 0 - - this.saveItemImage(itemId, { ...file }, isRepresentImage) - }) + await Promise.all( + files.map((file, i) => { + const isRepresentImage: boolean = i === 0 + this.saveItemImage(itemId, { ...file }, isRepresentImage) + }), + ) } async saveItemImage(itemId: number, @UploadedFiles() file: Express.Multer.File, isRepresentImage) { diff --git a/server/src/item-images/application/item-image.updater.ts b/server/src/item-images/application/item-image.updater.ts index db3147f..d82db4c 100644 --- a/server/src/item-images/application/item-image.updater.ts +++ b/server/src/item-images/application/item-image.updater.ts @@ -13,7 +13,7 @@ export class ItemImageUpdater { const { id } = items const itemImages = await this.itemImageRepository.findByItemOrderByItemImageIdAsc(id) - if (Array.isArray(itemImages) && itemImages.length === 0) { + if (!itemImages || itemImages.length === 0) { throw new ItemImageNotFoundException(`${id}에 해당하는 이미지를 찾을 수 없습니다.`) }