Skip to content

Commit

Permalink
[FIX] 커뮤니티 게시물 삭제 시 community_category_post 테이블 데이터도 삭제 #355
Browse files Browse the repository at this point in the history
  • Loading branch information
yubinquitous committed May 31, 2024
1 parent 17f3b28 commit 5ddc5d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion functions/api/routes/community/communityPostDELETE.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ module.exports = asyncWrapper(async (req, res) => {
.send(util.fail(statusCode.FORBIDDEN, responseMessage.FORBIDDEN));
}

await communityDB.deleteCommunityPost(dbConnection, communityPostId);
await communityDB.deleteCommunityPostById(dbConnection, communityPostId);
await communityDB.deleteCommunityCategoryPostByPostId(dbConnection, communityPostId);

res
.status(statusCode.OK)
Expand Down
17 changes: 15 additions & 2 deletions functions/db/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const getCommunityPostById = async (client, communityPostId) => {
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const deleteCommunityPost = async (client, communityPostId) => {
const deleteCommunityPostById = async (client, communityPostId) => {
const { rows } = await client.query(
`
UPDATE community_post
Expand All @@ -217,6 +217,18 @@ const deleteCommunityPost = async (client, communityPostId) => {
return convertSnakeToCamel.keysToCamel(rows[0]);
};

const deleteCommunityCategoryPostByPostId = async (client, communityPostId) => {
const { rows } = await client.query(
`
UPDATE community_category_post
SET is_deleted = TRUE
WHERE community_post_id = $1
`,
[communityPostId],
);
return convertSnakeToCamel.keysToCamel(rows[0]);
};

module.exports = {
getCommunityPostDetail,
getCommunityPosts,
Expand All @@ -231,5 +243,6 @@ module.exports = {
getCommunityCategoryPostsById,
reportCommunityPost,
getCommunityPostById,
deleteCommunityPost,
deleteCommunityPostById,
deleteCommunityCategoryPostByPostId,
};

0 comments on commit 5ddc5d6

Please sign in to comment.