-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [FEAT] 커뮤니티 게시물 삭제 API #355 * [FIX] 커뮤니티 게시물 삭제 시 community_category_post 테이블 데이터도 삭제 #355 * [FIX] statueCode 200에서 204로 변경
- Loading branch information
1 parent
3f8bf9e
commit 625da1e
Showing
6 changed files
with
128 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const util = require('../../../lib/util'); | ||
const statusCode = require('../../../constants/statusCode'); | ||
const responseMessage = require('../../../constants/responseMessage'); | ||
const db = require('../../../db/db'); | ||
const { communityDB } = require('../../../db'); | ||
const asyncWrapper = require('../../../lib/asyncWrapper'); | ||
|
||
/** | ||
* @route DELETE /community/:communityPostId | ||
* @desc 커뮤니티 게시글 삭제 | ||
* @access Private | ||
*/ | ||
|
||
module.exports = asyncWrapper(async (req, res) => { | ||
const { userId } = req.user; | ||
const { communityPostId } = req.params; | ||
|
||
const dbConnection = await db.connect(req); | ||
req.dbConnection = dbConnection; | ||
|
||
const post = await communityDB.getCommunityPostById(dbConnection, communityPostId); | ||
if (!post) { | ||
return res | ||
.status(statusCode.NOT_FOUND) | ||
.send(util.fail(statusCode.NOT_FOUND, responseMessage.NO_COMMUNITY_POST)); | ||
} | ||
if (post.userId !== userId) { | ||
return res | ||
.status(statusCode.FORBIDDEN) | ||
.send(util.fail(statusCode.FORBIDDEN, responseMessage.FORBIDDEN)); | ||
} | ||
|
||
await communityDB.deleteCommunityPostById(dbConnection, communityPostId); | ||
await communityDB.deleteCommunityCategoryPostByPostId(dbConnection, communityPostId); | ||
|
||
res | ||
.status(statusCode.NO_CONTENT) | ||
.send(util.success(statusCode.NO_CONTENT, responseMessage.DELETE_COMMUNITY_POST_SUCCESS)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters