diff --git a/src/controllers/category.controller.js b/src/controllers/category.controller.js index 9c6b19b..253c813 100644 --- a/src/controllers/category.controller.js +++ b/src/controllers/category.controller.js @@ -82,7 +82,7 @@ export const deleteCategoryData = async (req, res) => { const decoded = jwt.verify(token, process.env.JWT_SECRET); req.userID = decoded.id; - await deleteCategoryService(req); + const result = await deleteCategoryService(req); res.send(response(status.SUCCESS,"카테고리가 삭제되었습니다.")); } catch (error) { console.error(error); diff --git a/src/dtos/category.dto.js b/src/dtos/category.dto.js index a7cd749..3568bc4 100644 --- a/src/dtos/category.dto.js +++ b/src/dtos/category.dto.js @@ -38,15 +38,6 @@ export const add2CategoryResponseDTO = (category,categoryID) => { }; } -// 카테고리 수정 -export const fixCategoryResponseDTO = (category) => { - return { - "topCategoryId": category.top_category, - "categoryId": category.category_id, - "name": category.name, - }; -} - // 이동2 export const move2CategoryResponseDTO = (category,etc) => { return { diff --git a/src/models/category.dao.js b/src/models/category.dao.js index d74756c..08fe29b 100644 --- a/src/models/category.dao.js +++ b/src/models/category.dao.js @@ -21,7 +21,7 @@ export const getCategoryDAO=async (userID) => { // 상위 또는 하위 카테고리 추가 export const addCategoryDAO=async (req) =>{ try{ - const conn =await pool.getConnection(); + const conn = await pool.getConnection(); const result = await pool.query( "insert into category(name, user_id, top_category, created_at) values(?,?,?,?);", [req.name, req.user_id, req.top_category, req.created_at]); @@ -42,7 +42,13 @@ export const renameCategoryDAO = async (req) => { "update category set name = ? where id = ? and user_id = ?;", [req.name, req.category_id, req.user_id] ); + + const result = await pool.query( + "SELECT * FROM category WHERE id = ?", [req.category_id] + ) + conn.release(); + return result[0]; } catch (err) { console.error(err); throw new BaseError(status.PARAMETER_IS_WRONG); @@ -65,7 +71,7 @@ export const deleteCategoryDAO = async (req) => { // 비디오 삭제 const [videoIds] = await pool.query("SELECT id FROM video WHERE user_id = ? AND category_id = ?", [req.user_id, subCategory.id]); for (const videoIdObj of videoIds) { - await dropVideo({ videoID: videoIdObj.id }); + const dropedVideo = await dropVideo({ videoID: videoIdObj.id }); } // 하위 카테고리 삭제 const dropCategory = await pool.query("DELETE FROM category WHERE user_id = ? AND id = ?", [req.user_id, subCategory.id]); @@ -78,7 +84,7 @@ export const deleteCategoryDAO = async (req) => { // 비디오 삭제 const [videoIds] = await pool.query("SELECT id FROM video WHERE user_id = ? AND category_id = ?", [req.user_id, req.category_id]); for (const videoIdObj of videoIds) { - await dropVideo({ videoID: videoIdObj.id }); + const dropedVideo = await dropVideo({ videoID: videoIdObj.id }); } // 해당 카테고리 삭제 diff --git a/src/services/category.service.js b/src/services/category.service.js index e593ac6..2b86a35 100644 --- a/src/services/category.service.js +++ b/src/services/category.service.js @@ -2,7 +2,7 @@ import { BaseError } from "../../config/error.js"; import {status} from "../../config/response.status.js" -import { getCategoryResponseDTO,add1CategoryResponseDTO,add2CategoryResponseDTO,fixCategoryResponseDTO,move2CategoryResponseDTO,categoryTagResponseDTO,getCategoryIdResponseDTO} from "../dtos/category.dto.js"; +import { getCategoryResponseDTO,add1CategoryResponseDTO,add2CategoryResponseDTO,move2CategoryResponseDTO,categoryTagResponseDTO,getCategoryIdResponseDTO} from "../dtos/category.dto.js"; import { addCategoryDAO,getCategoryDAO,renameCategoryDAO,deleteCategoryDAO } from "../models/category.dao.js" import { move1CategoryDAO,move2CategoryDAO,move3CategoryDAO,getCategoryTagDAO } from "../models/category.dao.js" @@ -53,8 +53,8 @@ export const renameCategoryService = async (req) => { user_id : req.userID, category_id : req.params.categoryID, }; - await renameCategoryDAO(categoryData); - return fixCategoryResponseDTO(categoryData); + const result = await renameCategoryDAO(categoryData); + return getCategoryIdResponseDTO(result); }; // 카테고리 삭제 @@ -64,7 +64,7 @@ export const deleteCategoryService = async (req) => { category_id : req.params.categoryID, }; console.log("서비스 요청 정보", categoryData); - await deleteCategoryDAO(categoryData); + const deletedCategory = await deleteCategoryDAO(categoryData); } // 카테고리 이동1 (하위의 상위 카테고리가 변경될 때)