diff --git a/src/repositories/myRepository.js b/src/repositories/myRepository.js index a5ad902d74b40a80a5d7c8138a50bf65456a7510..d4af715c6f0927ade27d99175681732ceb36fcf1 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 658b94adc107d3c639c85645f23dd84d2f75d665..943a9fd49ceb85dac8c365bd5d48b152ef105ef6 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 89889658c110626fdc645a61bcae069c19b7bc58..f95edeb975ab5778db977e64c5eb84da44969078 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 1053ecba48db50324733e801ca8dea19b20d48c3..2a9c553afef474cb422491aa174a3b0c932b75db 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) {