From 0888fe4bf7fe4f9e1fc6b85ab79948a24dc045b0 Mon Sep 17 00:00:00 2001
From: LeeWxx <dnckd0903@naver.com>
Date: Mon, 2 Dec 2024 21:36:31 +0900
Subject: [PATCH] =?UTF-8?q?feat:=20=EC=8B=A4=EC=A0=9C=20=EC=9C=A0=EC=A0=80?=
 =?UTF-8?q?=EA=B0=80=20=EA=B0=80=EC=A7=80=EA=B3=A0=20=EC=9E=88=EB=8A=94=20?=
 =?UTF-8?q?=EB=B6=80=ED=92=88=EB=A7=8C=EC=9D=84=20=ED=95=84=ED=84=B0?=
 =?UTF-8?q?=EB=A1=9C=20=EB=B0=98=ED=99=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/repositories/partRepository.js | 11 ++++++-----
 src/routes/parts.js                |  2 --
 src/services/partService.js        |  2 +-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/repositories/partRepository.js b/src/repositories/partRepository.js
index e5553f0..4e453fa 100644
--- a/src/repositories/partRepository.js
+++ b/src/repositories/partRepository.js
@@ -32,11 +32,12 @@ const PartRepository = {
 
   async getFilterDataByTypeAndColumn(type, column) {
     const query = `
-      SELECT DISTINCT ${column}
-      FROM part_info_${type}
-      WHERE ${column} IS NOT NULL
-      ORDER BY ${column}
-    `;
+    SELECT DISTINCT p.${column}
+    FROM relations r
+    JOIN part_info_${type} p ON r.part_id = p.part_id -- id 대신 part_id 사용
+    WHERE p.${column} IS NOT NULL
+    ORDER BY p.${column}
+  `;
     const resp = await pool.query(query);
     return resp.rows.map((row) => row[column]);
   },
diff --git a/src/routes/parts.js b/src/routes/parts.js
index a6a9287..b995962 100644
--- a/src/routes/parts.js
+++ b/src/routes/parts.js
@@ -9,9 +9,7 @@ partRouter.get(
   '/',
   wrapAsync(async (req, res) => {
     const { partType, filters } = req.query;
-
     const parts = await PartService.getParts(partType, filters);
-
     return res.sendResponse('', 200, { parts });
   })
 );
diff --git a/src/services/partService.js b/src/services/partService.js
index 2e8d58c..0fa797d 100644
--- a/src/services/partService.js
+++ b/src/services/partService.js
@@ -52,7 +52,7 @@ const PartService = {
 
   async getParts(partType, filters) {
     if (!partType) {
-      throw new Error('파트 타입이 필요합니다.');
+      throw new ReportableError(400, '파트 타입이 필요합니다.');
     }
 
     let parsedFilters;
-- 
GitLab