Skip to content
Snippets Groups Projects
Commit b7f7c909 authored by Lee WooChang's avatar Lee WooChang
Browse files

Merge branch 'fix/update-combination-name' into 'main'

조합 이름 변경 에러 수정

See merge request !19
parents 4add93e5 668c3098
No related branches found
No related tags found
1 merge request!19조합 이름 변경 에러 수정
Pipeline #10820 passed
import pool from '../db.js'; import pool from '../db.js';
const myRepository = { 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) { async getCombinationsByUserId(userId) {
const query = ` const query = `
SELECT id, name SELECT id, name
...@@ -49,7 +73,7 @@ const myRepository = { ...@@ -49,7 +73,7 @@ const myRepository = {
async updateCombinationName(combinationId, newName) { async updateCombinationName(combinationId, newName) {
const query = ` const query = `
UPDATE combinations UPDATE combinations
SET name = $1, updated_at = NOW() SET name = $1
WHERE id = $2 WHERE id = $2
`; `;
const values = [newName, combinationId]; const values = [newName, combinationId];
......
...@@ -27,7 +27,7 @@ myRouter.patch( ...@@ -27,7 +27,7 @@ myRouter.patch(
wrapAsync(async (req, res) => { wrapAsync(async (req, res) => {
const { combinationId } = req.params; const { combinationId } = req.params;
const { newName } = req.body; const { newName } = req.body;
const userId = req.user.id; const userId = req.user?.userId;
if (!newName || typeof newName !== 'string') { if (!newName || typeof newName !== 'string') {
throw new ReportableError(400, '유효한 새로운 이름이 필요합니다.'); throw new ReportableError(400, '유효한 새로운 이름이 필요합니다.');
......
...@@ -79,7 +79,7 @@ const PartService = { ...@@ -79,7 +79,7 @@ const PartService = {
const allCombinations = await PartRepository.getAllCombinations(); const allCombinations = await PartRepository.getAllCombinations();
return allCombinations.map((combination) => ({ return allCombinations.map((combination) => ({
partIds: combination.partids, partIds: combination.partids,
}));; }));
}, },
async getFilteredCombinations(filters) { async getFilteredCombinations(filters) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment