From 668c3098564d8506534edf7bdc71b936032e0a51 Mon Sep 17 00:00:00 2001
From: LeeWxx <dnckd0903@naver.com>
Date: Sun, 8 Dec 2024 01:11:31 +0900
Subject: [PATCH] =?UTF-8?q?fix:=20combination=20=EC=9D=B4=EB=A6=84=20?=
 =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=20=EC=98=A4=EB=A5=98=20?=
 =?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/repositories/myRepository.js   | 26 +++++++++++++++++++++++++-
 src/repositories/partRepository.js |  2 +-
 src/routes/my.js                   |  2 +-
 src/services/partService.js        |  2 +-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/repositories/myRepository.js b/src/repositories/myRepository.js
index a5ad902..d4af715 100644
--- a/src/repositories/myRepository.js
+++ b/src/repositories/myRepository.js
@@ -1,6 +1,30 @@
 import pool from '../db.js';
 
 const myRepository = {
+  async checkUserExists(userId) {
+    const query = `
+      SELECT 1
+      FROM users
+      WHERE id = $1
+    `;
+    const values = [userId];
+
+    const { rows } = await pool.query(query, values);
+    return rows.length > 0;
+  },
+
+  async getCombinationById(combinationId) {
+    const query = `
+      SELECT id, name, owner_id AS "userId"
+      FROM combinations
+      WHERE id = $1
+    `;
+    const values = [combinationId];
+
+    const { rows } = await pool.query(query, values);
+    return rows.length > 0 ? rows[0] : null;
+  },
+
   async getCombinationsByUserId(userId) {
     const query = `
       SELECT id, name 
@@ -49,7 +73,7 @@ const myRepository = {
   async updateCombinationName(combinationId, newName) {
     const query = `
       UPDATE combinations
-      SET name = $1, updated_at = NOW()
+      SET name = $1
       WHERE id = $2
     `;
     const values = [newName, combinationId];
diff --git a/src/repositories/partRepository.js b/src/repositories/partRepository.js
index 658b94a..943a9fd 100644
--- a/src/repositories/partRepository.js
+++ b/src/repositories/partRepository.js
@@ -67,7 +67,7 @@ const PartRepository = {
   `;
 
     const result = await pool.query(query);
-    
+
     return result.rows;
   },
 
diff --git a/src/routes/my.js b/src/routes/my.js
index 8988965..f95edeb 100644
--- a/src/routes/my.js
+++ b/src/routes/my.js
@@ -27,7 +27,7 @@ myRouter.patch(
   wrapAsync(async (req, res) => {
     const { combinationId } = req.params;
     const { newName } = req.body;
-    const userId = req.user.id;
+    const userId = req.user?.userId;
 
     if (!newName || typeof newName !== 'string') {
       throw new ReportableError(400, '유효한 새로운 이름이 필요합니다.');
diff --git a/src/services/partService.js b/src/services/partService.js
index 1053ecb..2a9c553 100644
--- a/src/services/partService.js
+++ b/src/services/partService.js
@@ -79,7 +79,7 @@ const PartService = {
     const allCombinations = await PartRepository.getAllCombinations();
     return allCombinations.map((combination) => ({
       partIds: combination.partids,
-    }));;
+    }));
   },
 
   async getFilteredCombinations(filters) {
-- 
GitLab