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

feat: pc 이름 변경기능 추가

parent 21ba0ab2
Branches
No related tags found
1 merge request!14PC 이름 변경기능 추가
Pipeline #10787 passed
......@@ -45,6 +45,18 @@ const myRepository = {
return rows.length > 0 ? rows[0].combination_id : null;
},
async updateCombinationName(combinationId, newName) {
const query = `
UPDATE combinations
SET name = $1, updated_at = NOW()
WHERE id = $2
`;
const values = [newName, combinationId];
const { rowCount } = await pool.query(query, values);
return rowCount > 0;
},
};
export default myRepository;
......@@ -21,6 +21,24 @@ myRouter.get(
})
);
myRouter.patch(
'/pc/:combinationId/name',
authMiddleware,
wrapAsync(async (req, res) => {
const { pcId } = req.params;
const { newName } = req.body;
const userId = req.user.id;
if (!newName || typeof newName !== 'string') {
throw new ReportableError(400, '유효한 새로운 이름이 필요합니다.');
}
const result = await myService.updateCombinationName(userId, pcId, newName);
return res.status(200).json(result);
})
);
myRouter.get(
'/registration-code',
authMiddleware,
......
......@@ -124,6 +124,45 @@ const myService = {
return pcs;
},
async updateCombinationName(userId, combinationId, newName) {
if (!userId || !combinationId || !newName) {
throw new ReportableError(
400,
'유효한 사용자 ID, 조합 ID, 및 새로운 이름이 필요합니다.'
);
}
const userExists = await myRepository.checkUserExists(userId);
if (!userExists) {
throw new ReportableError(404, '사용자를 찾을 수 없습니다.');
}
const combination = await myRepository.getCombinationById(combinationId);
if (!combination) {
throw new ReportableError(404, '조합을 찾을 수 없습니다.');
}
if (combination.userId !== userId) {
throw new ReportableError(403, '해당 조합에 대한 권한이 없습니다.');
}
const updated = await myRepository.updateCombinationName(
combinationId,
newName
);
if (!updated) {
throw new ReportableError(
500,
'조합 이름을 업데이트하는 중 문제가 발생했습니다.'
);
}
return {
success: true,
message: '조합 이름이 성공적으로 변경되었습니다.',
};
},
};
export default myService;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment