Skip to content

Commit

Permalink
Merge pull request #176 from teamViNO/feature/category
Browse files Browse the repository at this point in the history
fix: await 사용 수정
  • Loading branch information
jainefer authored Feb 17, 2024
2 parents 8f6a30e + bb8aa17 commit dfb783c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/controllers/category.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions src/dtos/category.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions src/models/category.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
Expand All @@ -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]);
Expand All @@ -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 });
}

// 해당 카테고리 삭제
Expand Down
8 changes: 4 additions & 4 deletions src/services/category.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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);
};

// 카테고리 삭제
Expand All @@ -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 (하위의 상위 카테고리가 변경될 때)
Expand Down

0 comments on commit dfb783c

Please sign in to comment.